在discord.py中,当我使用超过1`on_message`时都无法工作,只有最后一个起作用
这是我的代码,on_message
在使用两次时不起作用,只有第二个正在使用。请帮我。
async def on_message(message):<br>
if message.content.startswith('-coinflip'):<br>
embedVar = discord.Embed(<br>
title="Toss",<br>
description=(f'You got {random.choice(heads_tails)}'),<br>
color=(0xFF0000))<br>
print(f'-coinflip command used by {message.author}')<br>
await message.channel.send(embed=embedVar)<br>
@client.event<br>
async def on_message(message):<br>
if message.content.startswith('-help'):<br>
embedVar = discord.Embed(<br>
title="Help arrived!",<br>
description="So, it looks like you need help, let me help you",<br>
colour=0xFF0000)<br>
embedVar.add_field(name="Bot Prefix", value="-", inline=False)<br>
embedVar.add_field(name="Moderation Commands",<br>
value="-help",<br>
inline=True)<br>
embedVar.add_field(name="Fun commands", value="-coinflip", inline=True)<br>
embedVar.set_thumbnail(<br>
url=<br>
"https://media.discordapp.net/attachments/923531605660815373/974248483479494686/charizard-mega-charizard-y.gif"<br>
)<br>
print(f'-help command used by {message.author}')<br>
await message.channel.send(embed=embedVar)<br>```
This is my code, and on_message
is not working when used twice, only the 2nd one is working. Please help me.
async def on_message(message):<br>
if message.content.startswith('-coinflip'):<br>
embedVar = discord.Embed(<br>
title="Toss",<br>
description=(f'You got {random.choice(heads_tails)}'),<br>
color=(0xFF0000))<br>
print(f'-coinflip command used by {message.author}')<br>
await message.channel.send(embed=embedVar)<br>
@client.event<br>
async def on_message(message):<br>
if message.content.startswith('-help'):<br>
embedVar = discord.Embed(<br>
title="Help arrived!",<br>
description="So, it looks like you need help, let me help you",<br>
colour=0xFF0000)<br>
embedVar.add_field(name="Bot Prefix", value="-", inline=False)<br>
embedVar.add_field(name="Moderation Commands",<br>
value="-help",<br>
inline=True)<br>
embedVar.add_field(name="Fun commands", value="-coinflip", inline=True)<br>
embedVar.set_thumbnail(<br>
url=<br>
"https://media.discordapp.net/attachments/923531605660815373/974248483479494686/charizard-mega-charizard-y.gif"<br>
)<br>
print(f'-help command used by {message.author}')<br>
await message.channel.send(embed=embedVar)<br>```
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是我写的答案,但无法发布:
您不能有2个
on_message
事件侦听器。您可以通过使用使用
喜欢这样的合并两个事件听众及其响应:
elif
与(如果)相同;在这种情况下,如果消息的content
不是以“ -coinflip”开头,并以“ -help”开头,它将创建并发送嵌入
。我已更换了全功能代码的
heads_tails
变量:另外,是“ -help” a MEDERATION 命令?并且,尝试自己搜索和解决此类问题。 stackoverflow不应该是第一个提出此类问题的地方。
Here's the answer I wrote but couldn't post:
You cannot have 2
on_message
event listeners. You can merge the two event listeners and their responses by usingif...elif
like this instead:elif
is the same aselse if
; in this case, if the message'scontent
doesn't start with "-coinflip" and starts with "-help", it creates and sends anEmbed
.I've replaced the
heads_tails
variable for a fully-functioning code:Also, is "-help" a moderation command? And, try searching for and solving such problems yourself. StackOverflow shouldn't be the first place to ask such questions.