【发布时间】:2021-08-14 05:35:08
【问题描述】:
我想从特定频道获取消息,有时它会获取其他频道,我基本上优先考虑它只选择这个特定频道。
代码
@client.event
async def on_message(message):
#Ignore messages that aren't sent in 0000000000
if message.channel.id == 0000000000:
return
#Ignore messages sent by the bot
if message.author == client.user:
return
基本上是想确保它只获取这个频道,如果 ID 匹配,它只会在那个频道内获取!
【问题讨论】:
-
为什么第一次忽略时有
else而不是return,应该是if message.channel.id != 0000000000: return -
那是一个错字!它会忽略频道。
-
代码仍然与 cmets 不匹配,修复其中一个,我猜 cmets 是正确的,因此,
message.channel.id ==应该是message.channel.id != -
是的,我知道 cmets 与我添加的代码不匹配,以便更容易理解我在做什么,我混合了一些 cmets。但是,您的代码有效,感谢您的帮助!
标签: python discord discord.py