【问题标题】:I want to stop the Discord Bot from running我想阻止 Discord Bot 运行
【发布时间】:2021-01-02 13:04:18
【问题描述】:

所以基本上我是在用一个不和谐的机器人做一些事情,我陷入了这个困境。

假设这是callBot_and_sendmessage函数

       def callBot_and_sendmessage(message):
                #wake the bot
                @client.event
                async def on_ready():    
                        await client.change_presence(activity = discord.Game(name='Do !help'))
             
                #send the message
                @client.event
                async def on_message(message):
                        channel = client.get_channel(channelId)
                        await channel.send(message)  

我的代码是这样的

message = input('Type a message: ')
callBot_and_sendmessage(message)
saveMessage(message)

函数saveMessage

def saveMessage(message):
    with open(file, 'w') as fileData:
        fileData.write(message)

我的程序不会调用saveMessage 函数 所以我需要一种方法来阻止 callBot_and_sendmessage 又名机器人在发送消息后运行

谁能帮我解决这个问题?

【问题讨论】:

    标签: python discord discord.py


    【解决方案1】:

    您可以使用client.close() 使机器人注销。或者,您可以将exit(0) 放在末尾(在channel.send 之后),以便在发送消息后脚本停止运行。

    【讨论】:

      猜你喜欢
      • 2023-01-23
      • 2021-07-13
      • 2021-07-21
      • 1970-01-01
      • 2019-02-13
      • 1970-01-01
      • 2021-09-15
      • 1970-01-01
      • 2021-11-04
      相关资源
      最近更新 更多