首页 > 解决方案 > Discord.py 消息固定?

问题描述

我已经尝试了多种不同的方法来使用带有 discord.py 的 bot / selfbot 来固定(我也想尝试取消固定)某个消息(它已经发送),这里有几个例子:

@pinner.event
async def on_message():
    if message.content == 'message im trying to pin':
    message.pin


@tasks.loop(seconds=1)
async def pin_message():
    message = ('message id ')
    await message.pin(message id)

我正在使用 Python 3.8 和最新版本的 discord.py API。

标签: pythondiscorddiscord.pypython-3.8

解决方案


为了固定消息,您必须首先拥有该消息,一旦您拥有它,您就可以await message.pin()

要取消固定,您可以使用await message.unpin()

机器人还必须获得manage_messages许可才能固定或取消固定消息。

这将固定用户触发命令的消息

@bot.command()
async def pin_message(ctx):
  await ctx.message.pin()

如果您想固定特定消息,则必须使用其中一个ctx.fetch_message(message_id)或者如果您有文本通道来获取它textchannel.fetch_message(message_id)

这将固定用户想要的消息:

@bot.command()
async def pin_this(ctx, message_id: int):
  message = await ctx.fetch_message(message_id)
  await message.pin()

可选:您还可以指定原因await message.pin(reason="your reason here")

文档:


推荐阅读