gpt4 book ai didi

python - discord.py bot 只响应一个命令

转载 作者:行者123 更新时间:2023-12-03 07:39:49 25 4
gpt4 key购买 nike

它在给定时间只显示其中一个命令。
如果我写 !hi!bye 它不会工作,但如果我写 !sing 它会输出 la la la
如果我在它之前切换角色,它会变成!hi!sing 不工作但是 !bye 工作并说 Goodbye!

import os

client = discord.Client()

@client.event
async def on_ready():
print('We have logged in as {0.user}'
.format(client))

@client.event
async def on_message(message):
if message.author == client.user:
return

if message.content.startswith('!hi'):
await message.channel.send('Hello!')

@client.event
async def on_message(message):
if message.author == client.user:
return

if message.content.startswith('!bye'):
await message.channel.send('Goodbye Friend!')

@client.event
async def on_message(message):
if message.author == client.user:
return

if message.content.startswith('!sing'):
await message.channel.send('la la la')

client.run(os.getenv('TOKEN'))```

最佳答案

您正在尝试使用多个事件,而不是像这样在一个事件中使用所有事件:

@client.event
async def on_message(message):
if message.author == client.user:
return

if message.content.startswith('!hi'):
await message.channel.send('Hello!')

elif message.content.startswith('!bye'):
await message.channel.send('Goodbye Friend!')

elif message.content.startswith('!sing'):
await message.channel.send('la la la')

此外,确保在其他事件中使用 elif 而不是 if。这应该可以做到。

关于python - discord.py bot 只响应一个命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65542062/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com