python - 我如何制作一个机器人,如果你做出反应,它将赋予 ua 与 python 的角色?
问题描述
所以,我一直在这样做:
from discord.ext import commands
from discord.utils import get
client = commands.Bot(command_prefix='><')
@client.event
async def on_ready():
print("I am ready Winson or not Winson :D")
@client.event
async def on_member_join(member):
channel = client.get_channel(744440768667844698)
message = await channel.send(f"Welcome to HaveNoFaith {member}, happy to be friends with you")
@client.command()
async def ping(ctx):
await ctx.send(f"Your Ping is {round(client.latency *1000)}ms")
@client.command()
async def Help(ctx2):
await ctx2.send("Hi, Im WelcomeBot v1.0...\n\nPrefix: ><\n\nCommands: ping\n help")
#然后我尝试在“欢迎等”消息中做类似的事情,如果他们对该消息中的“检查反应”做出反应,他们将在不和谐服务器中获得一个角色......
解决方案
您可以创建一个名为addrr
(添加反应角色)的命令,如下所示 -
@client.command()
@commands.guild_only()
@commands.has_permissions(administrator=True)
async def addrr(self, ctx, channel: discord.TextChannel, message: discord.Message, emoji: discord.Emoji,
role: discord.Role):
await ctx.send(f"Setting up the reaction roles in {channel.mention}.")
await message.add_reaction(emoji)
def check1(reaction, user):
return user.id is not self.client.user.id and str(reaction.emoji) in [f"{emoji}"]
while True:
try:
reaction, user = await self.client.wait_for("reaction_add", check=check1)
if str(reaction.emoji) == f"{emoji}":
await user.add_roles(role)
await message.remove_reaction(reaction, user)
else:
await message.remove_reaction(reaction, user)
except:
await message.delete()
break
它会像这样工作 -
><addrr <#channel mention> <message ID> <Emoji> <@Role Mention>
推荐阅读
- android - How to create Image view background like this?
- typescript - Mind Bending LinkedList Implementation in TypeScript
- python - Fetch non-empty cells from .xls file using pandas
- python - win10上的tensorflow-gpu安装问题
- javascript - 为什么 .charCodeAt() 不能确保您可以在此 Javascript 算法中找到丢失的字母?
- javascript - react中的自定义排序
- talend - Talend - 如何禁用检查额外功能?
- python - 无法通过烧瓶从 MySQL 检索数据
- java - AST 视图:Eclipse 插件不显示 ATS 的节点并显示不支持的 JLS
- tensorflow - 当我在 jupyter 中导入 tensorflow 时弹出以下错误