【问题标题】:AFK function stopped working when I hosted the bot in Digital Ocean当我在 Digital Ocean 中托管机器人时,AFK 功能停止工作
【发布时间】: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)

【问题讨论】:

    标签: python discord


    【解决方案1】:

    我想通了。问题是@client.event 没有工作,因为我有另一个client.event。当我将两者放在一起时,它可以正常工作!

    【讨论】:

      猜你喜欢
      • 2021-09-08
      • 1970-01-01
      • 1970-01-01
      • 2019-05-22
      • 2017-05-21
      • 1970-01-01
      • 1970-01-01
      • 2021-12-03
      • 1970-01-01
      相关资源
      最近更新 更多