当我的程序没有告诉我任何错误时,如何修复我的程序
How do I fix my program when it doesn't tell me any errors
我的程序没有输出任何错误告诉我出了什么问题,但是当我输入 .role 时我试图为我分配一个角色,它只是说不...走开
代码:
async def role(ctx):
if ctx.message.author == 'ItsJustLogic#9893':
user = ctx.message.author
await user.add_roles('The Great Mountain Chicken')
await ctx.send('done')
else:
await ctx.send('no... go away')
ctx.message.author
returns 你 discord.Member
所以你不能将它与字符串进行比较。您应该使用 ctx.author.name
和 ctx.author.discriminator
。 name
returns 你的名字,在本例中是 ItsJustLogic
, discriminator
returns 你 9893
。所以你可以通过组合来检查你的名字。
此外,您不能使用角色名称添加角色,您必须使用 discord.utils.get
或 guild.get_role()
获取角色,然后才能添加角色。
async def role(ctx):
member = ctx.author
if f'{member.name}#{member.discriminator}' == 'ItsJustLogic#9893':
role = discord.utils.get(ctx.guild.roles, name='The Great Mountain Chicken')
# or you can use role = ctx.guild.get_role(role id)
await member.add_roles(role)
await ctx.send('done')
else:
await ctx.send('no... go away')
我的程序没有输出任何错误告诉我出了什么问题,但是当我输入 .role 时我试图为我分配一个角色,它只是说不...走开
代码:
async def role(ctx):
if ctx.message.author == 'ItsJustLogic#9893':
user = ctx.message.author
await user.add_roles('The Great Mountain Chicken')
await ctx.send('done')
else:
await ctx.send('no... go away')
ctx.message.author
returns 你 discord.Member
所以你不能将它与字符串进行比较。您应该使用 ctx.author.name
和 ctx.author.discriminator
。 name
returns 你的名字,在本例中是 ItsJustLogic
, discriminator
returns 你 9893
。所以你可以通过组合来检查你的名字。
此外,您不能使用角色名称添加角色,您必须使用 discord.utils.get
或 guild.get_role()
获取角色,然后才能添加角色。
async def role(ctx):
member = ctx.author
if f'{member.name}#{member.discriminator}' == 'ItsJustLogic#9893':
role = discord.utils.get(ctx.guild.roles, name='The Great Mountain Chicken')
# or you can use role = ctx.guild.get_role(role id)
await member.add_roles(role)
await ctx.send('done')
else:
await ctx.send('no... go away')