【发布时间】:2021-04-17 15:36:39
【问题描述】:
我正在为我的不和谐服务器创建一个机器人,并且我正在尝试通过使用命令“.join”创建一个向某人添加角色的命令,然后提及您尝试赋予该角色的用户.下面是我用于该命令的代码。它不起作用
@client.command(help='Lets you join the specified faction. the user variable is who you are adding to the faction (type it as a mention. eg. @GlitchedData64)')
async def join(ctx, user, rolerequest):
author = ctx.message.author
rolelist = [r.mention for r in author.roles if r != ctx.guild.default_role]
roles = ", ".join(rolelist)
if admintoken in roles or ownertoken in roles:
if 'enders' in rolerequest or 'Enders' in rolerequest:
if enderstoken in roles:
await ctx.send(f'{user}, is already in that faction')
elif krypticstoken in roles:
await ctx.send(f'{user}, is already in a faction.\nTo join another faction they must leave the one they are currently in')
elif dotstoken in roles:
await ctx.send(f'{user}, is already in a faction.\nTo join another faction they must leave the one they are currently in')
else:
role = discord.utils.get(user.guild.roles, name="????Enders????")
await discord.Member.add_roles(user, role)
await ctx.send(f'{user.mention} has joined the Enders Faction')
print(f'{user} has joined the Enders Faction')
elif 'kryptics' in rolerequest or 'Kryptics' in rolerequest:
if krypticstoken in roles:
await ctx.send(f'{user}, is already in that faction')
elif enderstoken in roles:
await ctx.send(f'{user}, is already in a faction.\nTo join another faction they must leave the one they are currently in')
elif dotstoken in roles:
await ctx.send(f'{user}, is already in a faction.\nTo join another faction they must leave the one they are currently in')
else:
role = discord.utils.get(user.guild.roles, name="????????kryptics????????")
await discord.Member.add_roles(user, role)
await ctx.send(f'{user.mention} has joined the Kryptics Faction')
print(f'{user} has joined the Kryptics Faction')
elif 'dots' in rolerequest or 'Dots' in rolerequest:
if dotstoken in roles:
await ctx.send(f'{user}, is already in that faction')
elif krypticstoken in roles:
await ctx.send(f'{user}, is already in a faction.\nTo join another faction they must leave the one they are currently in')
elif enderstoken in roles:
await ctx.send(f'{user}, is already in a faction.\nTo join another faction they must leave the one they are currently in')
else:
role = discord.utils.get(user.guild.roles, name="????Dots????")
await discord.Member.add_roles(user, role)
await ctx.send(f'{user.mention} has joined the Dots Faction')
print(f'{user} has joined the Dots Faction')
else:
await ctx.send(f"I'm affraid that faction doesn't exist. you can create it with '.createfaction' followed by the name")
else:
await ctx.send(f'This command is not available to Non-administrator users')
我对制作机器人相当陌生,所以如果这是一个非常明显的答案,请告诉(我也在使用 discord.py 的 rewrite 分支)
【问题讨论】:
标签: python discord discord.py discord.py-rewrite