【问题标题】:python discord bot on_disconnect messagepython discord bot on_disconnect 消息
【发布时间】:2021-03-27 17:46:46
【问题描述】:

你好,我是编码新手,我正试图让这个不和谐的机器人在不和谐的情况下从在线变为离线时说“Azu-bot 离线”。

这是我为这个活动准备的代码

@client.event
async def on_disconnect():
    code_channel = client.get_channel(channel id)
    await code_channel.send("Azu-bot offline")

它所说的频道ID是频道的实际ID。

问题是当我杀死终端使机器人离线时,它从不发送消息,所以我需要帮助。

我还有一个事件,当它上线时会显示“Azu-bot online”,只要我运行它就可以工作。

也许问题是我为了让机器人离线而杀死的终端与正在运行使其发送“Azu-bot 离线”消息的代码的终端是同一个终端,这意味着由于终端已死,因此代码检测到离线事件不再运行,因此不会发送。如果是这样,那么我不知道如何解决这个问题。

求救求救求救求救求救求救求救求救:(

【问题讨论】:

    标签: python discord


    【解决方案1】:

    看看这个答案https://stackoverflow.com/a/56478987/13335890 它具有关闭命令的代码。可能对你有用。 这是python中的相同代码

    @client.command(aliases=["quit"])
    @commands.has_permissions(administrator=True)
    async def close(ctx):
        await client.close()
        print("Bot Closed")  # This is optional, but it is there to tell you.
    

    在client.close()之前发送离线消息

    【讨论】:

      猜你喜欢
      • 2021-10-30
      • 2018-07-07
      • 2019-07-04
      • 2020-08-25
      • 2021-08-12
      • 2021-08-27
      • 2021-08-12
      • 2019-03-23
      • 1970-01-01
      相关资源
      最近更新 更多