admin管理员组文章数量:1405170
I'm trying to create a discord commander that will lock a discord group so that even if my main account gets kicked out of the group, my bot takes over and adds itself, so that the group stays locked indefinitely.
but the “use_temp_bot_lock” function doesn't want to work it gives me the “missing acces” error which normally happens when the bot isn't in the group, but I'm sure the bot is in the group because I checked that the token was the right one and that even after I got kicked out of the group the bot that was supposed to take over was there too.
so I find myself asking for your help
here is my code:
import discord
from discord.ext import commands, tasks
import asyncio
import asyncio
spam_lock = {}
bot = commands.Bot(command_prefix=".", self_bot=True)
TOKENS = [
"MTIyNDQ3OTMxNTc1MjI5MTA2OA.***********************************", # VALID TOKEN
]
def get_alternate_token():
for token in TOKENS:
yield token
token_generator = get_alternate_token()
async def use_temp_bot_lock(token, friend, channel_ctx):
temp_bot = commands.Bot(command_prefix="!", self_bot=True)
async def temp_bot_main():
result = None
@temp_bot.event
async def on_ready():
nonlocal result
async def monitor_user_lock():
try:
while True:
await channel_ctx.edit() # HERE IT SAY "MISSING ACCES"
actual_member_count = len(channel_ctx.recipients) + (1 if bot.user not in channel_ctx.recipients else 0)
current_recipient_ids = [user.id for user in channel_ctx.recipients]
if actual_member_count < 10:
if friend.id not in current_recipient_ids:
try:
await channel_ctx.add_recipients(friend)
except Exception as e:
print(f"{friend.id}: {e}")
await asyncio.sleep(1.3113)
except Exception as e:
print(e)
await temp_bot.close()
task_lock = bot.loop.create_task(monitor_user_lock())
spam_lock[channel_ctx] = task_lock
await temp_bot.start(token)
return await temp_bot_main()
@botmand()
async def lock(ctx):
await ctx.message.delete()
if isinstance(ctx.channel, discord.GroupChannel):
channel_ctx = ctx.channel
async def fetch_user(user_id):
user = await bot.fetch_user(user_id)
return user
user = await fetch_user(1061247364112863322) # VALID USER ID
if user:
async def monitor_user_lock():
try:
while True:
await ctx.channel.edit()
actual_member_count = len(ctx.channel.recipients) + (1 if bot.user not in ctx.channel.recipients else 0)
current_recipient_ids = [user.id for user in ctx.channel.recipients]
if actual_member_count < 10:
if user.id not in current_recipient_ids:
try:
await ctx.channel.add_recipients(user)
except Exception as e:
print(f"{user.id}: {e}")
await asyncio.sleep(1.3113)
except Exception as e:
print(e)
new_token = next(token_generator)
await use_temp_bot_lock(new_token, user, channel_ctx)
task_lock = bot.loop.create_task(monitor_user_lock())
spam_lock[ctx.channel] = task_lock
to specify I use python 3.12.0 and discord.py 1.7.3 (all the other import are in their last version) I am not against changing librarie for my self bot because discord.py deleted the functionality to create self bot in their librarie
in addition to what I put in my current code I tried to get the channel of the group with its id using get_channel AND fetch_channel and testing with a real discord bot and a self bot present in the group the 2 do not work and lead to either for the real bot: do not find the group or for the self bot present in the group: block the code when await bot.get_channel(id) / await bot.fetch_channel(id) is done (I still don't know why it's doing this now)
本文标签: pythonDiscordpy (self bot)Missing AccesStack Overflow
版权声明:本文标题:python - Discord.py (self bot) : Missing Acces - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744259346a2597635.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论