【问题标题】:Discord.py not unpinning own bot's messagesDiscord.py 没有取消固定自己机器人的消息
【发布时间】:2020-08-19 19:00:45
【问题描述】:

我的测试代码是

@bot.command(name='test')
async def test(ctx):
    message = await ctx.send('test')
    channel = ctx.channel
    message = await channel.fetch_message(message.id)
    await message.pin()
    await message.unpin()

机器人将消息固定,但不会取消固定。

【问题讨论】:

    标签: discord discord.py


    【解决方案1】:

    我测试了代码,它对我来说很好。

    注意- Discord 只显示某人已置顶该消息的消息,但 Discord 不显示是否有人取消置顶,您需要在置顶消息中查看。

    【讨论】:

    • 我现在测试了它,它也可以工作。我不知道为什么上次没有用,但在我发布问题之前,频道中的代码是channel = message.channel
    • 您应该注意的是,当您调用await message.pin() 时,如果您成功将该命令发送到 discord,它将返回。它确保命令完成。因此,您可能会遇到不和谐服务器在 pin 之前收到 unpin() 的竞争条件。
    【解决方案2】:
    import discord
    from discord.ext import commands
    
    bot = commands.Bot(command_prefix = '!')
    
    @bot.event
    async def on_ready():
        print('Logged successfully!')
    
    @bot.command()
    async def test(ctx):
        message = await ctx.send('test')
        await message.pin()
        await message.unpin()
    
    bot.run('BOT_TOKEN_HERE')
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-08-05
      • 2020-11-07
      • 1970-01-01
      • 1970-01-01
      • 2020-08-16
      • 2021-09-14
      • 2020-12-03
      • 2022-01-05
      相关资源
      最近更新 更多