我已经将规则嵌入到我的不和谐服务器中,并且嵌入也有一个 React , React 是一个复选标记(✅)。如果你对带有该复选标记的嵌入内容做出 React ,则将获得“验证”角色,并且你的 React 将被删除。
因此,它总是一种 React ,如果你做出 React ,你将获得“验证”角色,并且你的 React 将被删除。但这就是问题所在,当我做出 React 并且我的 React 也不会被删除时,我也没有得到我的角色。我没有任何错误,不知道如何解决。
这是我的代码
@bot.command(name='rules', pass_ctx=True)
async def rules(ctx):
rules_embed = discord.Embed(title='DISCORD RULES', color=0xf30000)
rules_embed.add_field(name="**1. No spamming** ", value="Don't send a lot of small/big messages right after "
"each other. Do not disrupt chat by spamming.",
inline=False)
rules_embed.add_field(name="**2. No NSFW material** ", value="This is a community server and not meant to "
"share this kind of material.", inline=False)
rules_embed.add_field(name="**3. No bullying or threats** ", value="Threats to other users of DDoS(Distributed "
"Denial of Service), Death, DoX/Doxx, abuse, "
"and other "
"malicious threats are absolutely not okay.",
inline=False)
rules_embed.add_field(name="**4. Don't beg for ranks** ", value="Don't beg for staff or other ranks", inline=False)
rules_embed.add_field(name="**5. No racism** ", value="Racism is absolutely not okay in this discord server",
inline=False)
rules_embed.add_field(name="**6. Have fun** ", value="Just have fun and be nice", inline=False)
send_rules = await ctx.message.channel.send(embed=rules_embed)
reactions = ['✅']
for i in reactions:
await send_rules.add_reaction(i)
@bot.event
async def on_raw_reaction_add(payload):
channel = bot.get_channel(payload.channel_id)
message = await channel.fetch_message(payload.message_id)
guild = bot.get_guild(payload.guild_id)
reaction = discord.utils.get(message.reactions, emoji=payload.emoji.name)
# only work if it is the client
if payload.member.id == bot.user.id:
return
if payload.message_id == 784182764009947177 and reaction.emoji == '✅':
roles = discord.utils.get(guild.roles, name='Verify')
await payload.member.add_roles(roles)
await reaction.remove(payload.member)
谢谢你的帮助!
你在代码中有几个错误,我已修复它们并评论了其中一些。请检查以下代码。
@bot.event
async def on_raw_reaction_add(payload):
#You forgot to await the bot.get_channel
channel = await bot.get_channel(payload.channel_id)
message = await channel.fetch_message(payload.message_id)
guild = bot.get_guild(payload.guild_id)
#Put the following Line
member = guild.get_member(payload.user_id)
reaction = discord.utils.get(message.reactions, emoji=payload.emoji.name)
# only work if it is the client
if payload.user_id == bot.user.id:
return
if payload.message_id == 784182764009947177 and reaction.emoji == '✅':
roles = discord.utils.get(guild.roles, name='Verify')
await member.add_roles(roles)
await reaction.remove(payload.member)
我尝试了您发送的代码,但是没有用,我遇到了一些错误。这些是错误``文件“ C:/Users/Admin/PycharmProjects/Rosy.Dc.py/main.py”,on_raw_reaction_add通道中的第97行=等待bot.get_channel(payload.channel_id)TypeError:对象TextChannel可以'不能在'await'表达式中使用
从bot.get_channel中删除await,然后尝试。
哦,对不起,我应该已经读过这个错误了,但是非常感谢您的帮助,它现在可以正常工作!