首页 > 解决方案 > Discord.py 在频道命令中取消固定消息?

问题描述

到目前为止,我得到的是:

@Bot.command()
async def unpin(ctx, amount = None):
    await ctx.message.delete()
    channel = str(ctx.channel)
    x = 0
    amount = int(amount)
    if amount == 0:
        await ctx.send("How many messages do you want to unpin, max is 50.")
    else:
        pins = await channel.pins()
        for message in pins:
                await message.unpin()
                x+=1
        x1 = str(x)
        await ctx.send(f"Unpinned {x} messages from #{channel}")

我的问题在于pins = await channel.pins()- 我不知道如何访问频道中的固定消息。如果有人可以提供帮助,将不胜感激。

标签: discord.pydiscord.py-rewrite

解决方案


您将ctx.channelin 返回到一个字符串。这就是您无法访问引脚的原因。如果您将行更改channel = str(ctx.channel)channel = ctx.channel,您的问题将得到解决。

而且,您应该将参数更改amount=Noneamount=0.


推荐阅读