Discord.py-使机器人对自己的消息做出反应
我试图使我的不和谐机器人对自己的信息做出反应。系统的工作方式如下:
一个人使用命令!! bug-并在DM中收到一条消息,她/她应该回答这些问题。然后,无论他/她回答了什么,都会将嵌入的消息传送到管理员文本通道。
但是我需要添加3个表情符号,或与三种不同的表情符号反应。根据管理员的选择,它将再次传输消息。因此,如果管理员对等于“固定”的表情符号做出反应,它将被移动到“固定”文本通道(整个消息)。
我对此进行了大量研究,但只发现了有关旧discord.py的线索,意思是await bot.add_react(emoji)
-但据我所知, 它不再有效!
这是我的代码:
import discord
from discord.ext import commands
import asyncio
TOKEN = '---'
bot = commands.Bot(command_prefix='!!')
reactions = [":white_check_mark:", ":stop_sign:", ":no_entry_sign:"]
@bot.event
async def on_ready():
print('Bot is ready.')
@bot.command()
async def bug(ctx, desc=None, rep=None):
user = ctx.author
await ctx.author.send('```Please explain the bug```')
responseDesc = await bot.wait_for('message', check=lambda message: message.author == ctx.author, timeout=300)
description = responseDesc.content
await ctx.author.send('````Please provide pictures/videos of this bug```')
responseRep = await bot.wait_for('message', check=lambda message: message.author == ctx.author, timeout=300)
replicate = responseRep.content
embed = discord.Embed(title='Bug Report', color=0x00ff00)
embed.add_field(name='Description', value=description, inline=False)
embed.add_field(name='Replicate', value=replicate, inline=True)
embed.add_field(name='Reported By', value=user, inline=True)
adminBug = bot.get_channel(733721953134837861)
await adminBug.send(embed=embed)
# Add 3 reaction (different emojis) here
bot.run(TOKEN)
-
在discord.py@rewrite中,您必须使用
discord.Message.add_reaction
:emojis = ['emoji 1', 'emoji_2', 'emoji 3'] adminBug = bot.get_channel(733721953134837861) message = await adminBug.send(embed=embed) for emoji in emojis: await message.add_reaction(emoji)
然后,要利用反应,您必须使用
discord.on_reaction_add
事件。当某人对消息作出反应并返回一个Reaction
对象和一个User
对象时,将触发此事件:@bot.event async def on_reaction_add(reaction, user): embed = reaction.embeds[0] emoji = reaction.emoji if user.bot: return if emoji == "emoji 1": fixed_channel = bot.get_channel(channel_id) await fixed_channel.send(embed=embed) elif emoji == "emoji 2": #do stuff elif emoji == "emoji 3": #do stuff else: return
注意:你必须更换
"emoji 1"
,"emoji 2"
并"emoji 3"
用你的表情图案。add_reactions
接受:- 全球表情符号(如😀),你可以复制emojipedia
- 原始unicode(您尝试过的)
- 不和谐表情符号:
\N{EMOJI NAME}
- 自定义不和谐表情符号(可能有一些更好的方法,经过少量研究我就提出了)
async def get_emoji(guild: discord.Guild, arg): return get(ctx.guild.emojis, name=arg)