[英]How do i make my discord.py bot react to all images sent in a channel
I am using this code but it crashes when i launch it, i want the bot to react with the custom emoji from my server (:okay:) to every image sent in a specific channel.我正在使用此代码,但是当我启动它时它崩溃了,我希望机器人对来自我的服务器的自定义表情符号 (:okay:) 对在特定通道中发送的每个图像做出反应。 Anyone knows why?
有谁知道为什么?
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)
You need to have the message_content
intent enabled to receive message attachments.您需要启用
message_content
意图才能接收消息附件。
intents = discord.Intents.default()
intents.message_content = True
bot = commands.Bot(command_prefix = '//', intents=intents)
There is no attachment
attribute in the Message
class it's, attachments
instead. Message
类中没有attachment
属性,而是attachments
。 Also, this is how you use and operator in an if statement:此外,这也是您在 if 语句中使用 and 运算符的方式:
if message.channel.id == 929345014205653014 and message.attachments:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.