当我在Digital Ocean中托管bot时,AFK功能停止工作

时间:2020-09-09 12:43:28

标签: python discord

我问了一个afk函数here,到现在为止,它运行良好。昨天,我在数字海洋中托管了该bot,以便它可以24/7全天候在线(我不知道这是否会影响bot的功能,但以防万一),从那时起,每当有人使用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)

1 个答案:

答案 0 :(得分:0)

我知道了。问题是@ client.event无法正常工作,因为我还有另一个client.event。当我将它们放在一起时,它可以正常工作!

相关问题