所以基本上我是在用一个不和谐的机器人做一些事情,我被困在这里面了
假设这是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
即bot运行
有人能帮我吗
您可以使用client.close()使bot注销。或者,您可以将
exit(0)
放在末尾(在channel.send
之后),以便在发送消息后脚本停止运行相关问题 更多 >
编程相关推荐