discord - 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("❌")
解决方案
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("❌")
推荐阅读
- c - 如何打印 gcc 默认对齐编号?
- php - PHP - Praneeth Madush Advanced-PHP-Login-System 脚本安全吗?
- android - 如何将 DEX 版本更改为 37,同时将 targetSdkVersion 保持在 30?
- python-3.x - 在 Pytest 固定装置内使用时,Python 日志不会记录
- debugging - b-table (Firefox) 上的图形错误
- asp.net-core - 是否可以有一个集线器的单例实例?
- python - Python json通过特定键值在列表中查找字典
- javascript - 如果选中,则获取图像的 url
- python - Python打印不同的值
- python - 将二维数组传递给 sklearn.metrics.recall_score 时,为什么会出现 ValueError?