Discord bot无法对消息添加表情反应的问题该如何解决?
Discord Bot 消息自动添加表情反应Bug修复方案
你代码里存在3个核心问题,对应修复逻辑如下:
- 频道ID类型匹配错误
discord库返回的message.channel.id为整数类型,你的判断条件中使用了字符串"77777"进行匹配,永远无法触发对应逻辑,需要去掉引号改为整数格式。 - 添加反应的调用方法错误
discord.py v1.0之后的版本已经移除了bot.add_reaction方法,正确调用方式是通过消息对象本身的add_reaction方法执行操作。 - 缺少bot自身消息过滤逻辑
未过滤bot自己发送的消息时可能触发循环响应,建议补充对应判断条件。
修正后完整可运行代码:
import discord from discord.ext import commands import asyncio intents = discord.Intents.all() bot = commands.Bot(command_prefix='!', intents=intents) @bot.event async def on_ready(): print("whatever_text_u_want_here") @bot.event async def on_message(message): # 过滤bot自身消息,避免循环触发 if message.author.bot: return # 频道ID改为整数类型 if message.channel.id == 77777: # 调用消息对象的添加反应方法 await message.add_reaction("🖐") # 若后续需要使用!前缀指令保留该行,无指令需求可删除 await bot.process_commands(message) bot.run("替换为你的Bot Token")
内容的提问来源于stack exchange,提问作者Juan
相关产品推荐
相关产品推荐

