【问题标题】:How to ignore other channels?如何忽略其他渠道?
【发布时间】: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


【解决方案1】:
@client.event
async def on_message(message):
    #Ignore messages that aren't sent in 0000000000
    if message.channel.id == 0000000000:
        #bot do what you want just in 0000 channel example:
        await message.delete() #delete every message which is sent in 0000 channel.

    if message.channel.id != 111111111:
        #ignores only 111111 channel, ( thats mean if message is not in 1111)
        return

    #Ignore messages sent by the bot
    if message.author == client.user:
        return

【讨论】:

    猜你喜欢
    • 2021-10-29
    • 1970-01-01
    • 1970-01-01
    • 2018-10-23
    • 2010-12-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-24
    相关资源
    最近更新 更多