【发布时间】:2020-09-09 12:43:28
【问题描述】:
我询问了一个 afk 函数here,它一直运行良好。昨天我在 Digital Ocean 中托管了机器人,这样它就可以 24/7 在线(我不知道这是否会影响机器人的功能,但以防万一)从那时起,每当有人使用 afk 功能时, bot 不会发送“此用户是 afk”消息,并且用户无法撤消 afk,除非他们再次调用它。我很迷茫,因为我没有更改此功能的任何内容,但它停止了工作。提前致谢。 我的代码:
afkdict = {}
@client.command(name = "afk", brief = "Away From Keyboard",
description = "I'll give you the afk status and if someone pings you before you come back, I'll tell "
"them that you are not available. You can add your own afk message!")
async def afk(ctx, message = "They didn't leave a message!"):
global afkdict
if ctx.message.author in afkdict:
afkdict.pop(ctx.message.author)
await ctx.send('Welcome back! You are no longer afk.')
else:
afkdict[ctx.message.author] = message
await ctx.send("You are now afk. Beware of the real world!")
@client.event
async def on_message(message):
global afkdict
if message.author in afkdict:
afkdict.pop(message.author)
await message.channel.send('Welcome back! You are no longer afk.')
for member in message.mentions:
if member != message.author:
if member in afkdict:
afkmsg = afkdict[member]
await message.channel.send(f"Oh noes! {member} is afk. {afkmsg}")
await client.process_commands(message)
【问题讨论】: