首页 > 解决方案 > How do I check to see if the channel id is equal to something

问题描述

I'm trying to make and event that checks to see if the channel id is equal to a specific id, if it is then the bot adds a reaction to that message. I'm not quite sure how to do this and have looked up many solutions but none of them help. There are some errors in the code that I still have to figure out like channel.id is not and actual command. Here is my code:

@client.event
async def on_message(message):
await discord.Client.get_channel(<channel_id>)

    if channel.id == <channel_id>:
      await message.add_reaction("✔️")
      await message.add_reaction("❌&quot;)

标签: discorddiscord.py

解决方案


discord.Client是一个类型,而不是一个实例。并且里面有一个message属性discord.Message

@client.event
async def on_message(message):
    if message.channel.id == <channel_id>:
      await message.add_reaction("✔️")
      await message.add_reaction("❌&quot;)

推荐阅读