好的,所以我正在尝试执行此 afk 命令,它似乎确实有效,但是一旦我放置 afk,机器人就会将其删除,
我的 main.py
中有这个空字典:
client=commands.Bot(...)
client.afk={}
代码:
@commands.command()
async def afk(self, ctx, reason=None):
self.client.afk[ctx.author]={'message': reason, 'time': ctx.message.created_at}
await ctx.send("You are now afk.")
@commands.Cog.listener()
async def on_message(self, message):
if message.author.bot:return
elif message.author in self.client.afk:
self.client.afk.pop(message.author)
await message.channel.send(f"Welcome back {message.author.mention}!")
elif message.mentions:
for mention in message.mentions:
mentioned_afk_user=self.client.afk.get(mention, None)
if mentioned_afk_user:
await message.channel.send(f"{message.author.mention}, **{mention.name}#{mention.discriminator}** has been AFK since <t:{int(mentioned_afk_user['time'].timestamp())}:R>, Reason: {mentioned_afk_user['message']}")