简体   繁体   English

如何制作一个对聊天中所有消息的反应起作用的不和谐机器人?

[英]How to make a discord bot that gives a role on reaction of all messages on chat?

I'm trying to make a discord bot to automate the giving of a certain role, the members receive the role when they react to all messages on a especific chat.我正在尝试制作一个不和谐的机器人来自动分配某个角色,当成员对特定聊天中的所有消息做出反应时,他们就会收到该角色。

I started making bots in python recently and i have no clue of how to do it我最近开始在 python 中制作机器人,但我不知道该怎么做

Works only for Discord.py 2.o仅适用于 Discord.py 2.o

@bot.command()
async def reactionroles(ctx):
    msg=await ctx.send("Reaction Roles!")
    await msg.add_reaction('🎂')
    await msg.add_reaction('🐶')


@bot.event
async def on_raw_reaction_add(payload):
    channel = await bot.fetch_channel(payload.channel_id)
    message = await channel.fetch_message(payload.message_id)
    user = await bot.fetch_user(payload.user_id)
    emoji = payload.emoji
    emoemoji=f"{emoji}"
    if payload.user_id != 941728904694075442:#your bot id
     if emoemoji=='🎂':
      role=ctx.guild.get_role(981534767185002506)#cake role id
      if role in user.roles:
         await user.remove_roles(role)
         emd=discord.Embed(title="Removed the Cake role",color=0x4582e6)
      else:
         await user.add_roles(role)
         emd=discord.Embed(title="Added the Cake role",color=0x4582e6)
      emd.set_author(name=user.display_name, icon_url=user.display_avatar.url)
      await message.send(embed=emd)
     if emoemoji=='🐶':
      role=ctx.guild.get_role(981534767185002506)#dog role id
      if role in user.roles:
         await user.remove_roles(role)
         emd=discord.Embed(title="Removed the Dog role",color=0x4582e6)
      else:
         await user.add_roles(role)
         emd=discord.Embed(title="Added the Dog role",color=0x4582e6)
      emd.set_author(name=user.display_name, icon_url=user.display_avatar.url)
      await message.send(embed=emd)



@bot.event
async def on_raw_reaction_remove(payload):
    channel = await bot.fetch_channel(payload.channel_id)
    message = await channel.fetch_message(payload.message_id)
    user = await bot.fetch_user(payload.user_id)
    emoji = payload.emoji
    emoemoji=f"{emoji}"
    if payload.user_id != 941728904694075442:#your bot id
     if emoemoji=='🎂':
      role=ctx.guild.get_role(981534767185002506)#cake role id
      if role in user.roles:
         await user.remove_roles(role)
         emd=discord.Embed(title="Removed the Cake role",color=0x4582e6)
      else:
         await user.add_roles(role)
         emd=discord.Embed(title="Added the Cake role",color=0x4582e6)
      emd.set_author(name=user.display_name, icon_url=user.display_avatar.url)
      await message.send(embed=emd)
     if emoemoji=='🐶':
      role=ctx.guild.get_role(981534767185002506)#dog role id
      if role in user.roles:
         await user.remove_roles(role)
         emd=discord.Embed(title="Removed the Dog role",color=0x4582e6)
      else:
         await user.add_roles(role)
         emd=discord.Embed(title="Added the Dog role",color=0x4582e6)
      emd.set_author(name=user.display_name, icon_url=user.display_avatar.url)
      await message.send(embed=emd)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM