简体   繁体   English

如何让我的 discord.py 机器人对频道中发送的所有图像做出反应

[英]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.

相关问题 如何使用 discord.py 制作一个检查某个服务器通道中所有消息的机器人 - How do I use discord.py to make a bot that checks through all messages in a certain server channel (discord.py) 如何让我的机器人读取发送给它的 DM 并打印它们或将它们发送到特定频道 - (discord.py) How do I get my bot to read DM's that are sent to it and either print them or send them to a specific channel 如何让我的 discord.py 机器人向我选择的频道发送我选择的消息? - how can i make my discord.py bot send a message i choose to a channel i choose? 如何让我的机器人从用户运行命令的位置获取通道 ID? (不和谐.py) - How do I make my bot get the channel Id from where the user ran the command from? (Discord.py) 如何让我的 discord.py 机器人删除在特定频道上发送的每条消息? - How can I make my discord.py bot delete every message send on a specific channel? 如何让我的机器人在 discord.py 中发送编辑过的图像? - How to make my bot send edited images in discord.py? 如何为我的邀请跟踪器 discord 机器人制作排行榜? discord.py - How do i make a leaderboard for my invite tracker discord bot? discord.py 我如何制作使我的机器人离开服务器的命令(discord.py) - How do i make a command that make my bot leave from the server (discord.py) 如何在heroku上托管我的discord.py机器人? - How do I host my discord.py bot on heroku? 如何让我的 discord.py 机器人向我重复触发词? - How do I make my discord.py bot repeat the trigger word back to me?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM