将字符串转换为频道ID

时间:2020-04-17 09:45:23

标签: python discord discord.py

我有一个用于手动设置秘密频道ID的命令:

@client.command(aliases=['secret', 'setSecretChannel'])
@commands.has_permissions(administrator=True)
async def set_secret_channel(ctx, id):
    global secret_channel_id
    secret_channel_id = id
    await ctx.send("ID set")

另一个命令使用secret_channel_id将用户移至秘密频道:

@client.command()
@commands.has_role('VIP')
async def joinSecret(ctx, password):
    author = ctx.message.author
    if password == joinSecret_password:
        await author.move_to(secret_channel_id)
        await ctx.send("Password correct")
    else:
        await ctx.send("Password incorrect")
    # delete author's message

但是,发生以下错误:

AttributeError: 'str' object has no attribute 'id'

是否可以将字符串转换为频道ID?

编辑

await author.move_to(int(secret_channel_id))

转换为int似乎也不起作用,现在的错误是:

AttributeError: 'int' object has no attribute 'id'

1 个答案:

答案 0 :(得分:0)

我知道了,现在可以了。我不得不改变

await author.move_to(secret_channel_id)

await author.move_to(client.get_channel(int(secret_channel_id)))