【问题标题】:Discord.py rolesDiscord.py 角色
【发布时间】:2021-09-30 18:08:52
【问题描述】:

如果作者有角色,我想发送消息,但是如果我尝试此代码它不起作用(角色的 id 是正确的)。

@client.command()
async def role(ctx):
    roles = ctx.author.roles
    for x in roles:
        if x.id == '850644250152665098':
await ctx.send("Role")

【问题讨论】:

  • ID 是整数,而不是字符串

标签: python discord discord.py roles


【解决方案1】:

discord.Role.id 返回一个整数值。这意味着您无法将其与字符串进行比较。您所要做的就是将if x.id == '850644250152665098': 更改为if x.id == 850644250152665098:

【讨论】:

  • 谢谢,我试图解决这个问题,但一无所获。
【解决方案2】:

除了最后一行没有很好地缩进之外,您正在将 strint 进行比较

@client.command()
async def role(ctx):
    for role in ctx.author.roles:
        if role.id == 850644250152665098:
            await ctx.send(f"Role {role.name} has been found")

【讨论】:

    猜你喜欢
    • 2021-04-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-10
    • 2021-06-02
    • 1970-01-01
    • 2021-07-06
    相关资源
    最近更新 更多