像标题一样,我需要制作一个可以以某种格式赋予角色的机器人。我已经设置了机器人以及所有东西,它可以执行基本命令。我想要它做的一个例子如下:
User: !!roles
Bot: Who do you want to give roles to?
User: User1 User2 User3 User4 (etc...)
Bot: What role do you want to give them?
User: Admin (Or rank1 rank2 etc...)
这是我创建的代码(是MESS):
@client.command(name="roles")
async def _roles(ctx):
if ctx.message.author.server_permissions.administrator:
global times_used
times_used = times_used + 1
await ctx.send(f"type who you want to give roles to, type cancel to cancel:")
# This will make sure that the response will only be registered if the following
# conditions are met:
def check(msg):
return msg.author == ctx.author and msg.channel == ctx.channel
try:
msg = await client.wait_for("message", check=check, timeout=120) # 120 seconds to reply
except asyncio.TimeoutError:
await ctx.send("Sorry, you didn't reply in time!")
if(msg.content == "cancel"):
return
else:
role = get(message.server.roles, name=role_to_give)
content_split = msg.content.split()
for user in content_split:
await client.add_roles(user, role)
else:
msg = "You're an average joe {0.author.mention}".format(ctx.message)
await client.send_message(ctx.message.channel, msg)
return
我正在使用python 3.8.3,将不胜感激!