我如何使我的discord.py bot对通道中发送的所有图像作出反应?



我正在使用这段代码,但当我启动它时它崩溃了,我希望机器人从我的服务器(:好吧:)到在特定通道中发送的每个图像的自定义表情符号作出反应。有人知道为什么吗?

import discord
from discord.ext    import commands
from discord.ext.commands   import Bot
import asyncio

bot = commands.Bot(command_prefix = '//')

@bot.event
async def on_ready():
print ("I have awoken")
async def react(message):
custom_emojis = [
"<:okay:942697477507801098>"                                                                               
]
guild_emoji_names = [str(guild_emoji) for guild_emoji in message.guild.emojis]
for emoji in custom_emojis:
#print(emoji, guild_emoji_names)                
#print(emoji in guild_emoji_names)
if emoji in guild_emoji_names:
await message.add_reaction(emoji)
@bot.event                                             
async def on_message(message):
if message.channel.id == 929345014205653014: and 
if message.attachment:
await react(message)

您需要启用message_content意图以接收消息附件。

intents = discord.Intents.default()
intents.message_content = True
bot = commands.Bot(command_prefix = '//', intents=intents)

Message类中没有attachment属性,而是attachments。另外,下面是在if语句中使用操作符的方法:

if message.channel.id == 929345014205653014 and message.attachments:

最新更新