Python 当程序不';不要告诉我任何错误

Python 当程序不';不要告诉我任何错误,python,discord.py,discord.py-rewrite,Python,Discord.py,Discord.py Rewrite,我的程序不会输出任何错误来告诉我出了什么问题,但我正在尝试在键入时为我分配一个角色。角色只是说不。。。走开 代码: ctx.message.author返回您的discord.Member,因此您无法将其与字符串进行比较。您应该使用ctx.author.name和ctx.author.discriminatorname返回名称,在本例中是ItsJustLogic,而discriminator返回9893。所以你可以把它们结合起来检查你的名字 此外,您不能使用角色名称添加角色,您必须使用disco

我的程序不会输出任何错误来告诉我出了什么问题,但我正在尝试在键入时为我分配一个角色。角色只是说不。。。走开

代码:


ctx.message.author
返回您的
discord.Member
,因此您无法将其与字符串进行比较。您应该使用
ctx.author.name
ctx.author.discriminator
name
返回名称,在本例中是
ItsJustLogic
,而
discriminator
返回
9893
。所以你可以把它们结合起来检查你的名字

此外,您不能使用角色名称添加角色,您必须使用
discord.utils.get
guild.get_role()
获取角色,然后才能添加角色

异步定义角色(ctx):
成员=ctx.author
如果f'{member.name}{member.discriminator}'='ItsJustLogic#9893':
role=discord.utils.get(ctx.guild.roles,name='TheGreat Mountain Chicken')
#或者您可以使用role=ctx.guild.get\u角色(角色id)
等待成员。添加_角色(角色)
等待ctx.send('done')
其他:
等待ctx发送(“不……走开”)

你确定
ctx.message.author
ItsJustLogic\9893
?我会添加一个日志或断点来查看。如果它没有告诉您有什么问题,那么可能没有什么问题。“说‘不……走开’”似乎是代码的一种有效行为。你应该更好地解释你正在尝试做什么,你期望得到什么输出,以及你得到了什么。并且,正如@Phix所说,做任何你需要做的事情来确保你知道你的代码真正在做什么(通过调试器、打印语句或日志语句)。说如果发生了什么事情,它应该提高。
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')