Discord.py消息固定?

2024-10-16 20:45:54 发布

您现在位置:Python中文网/ 问答频道 /正文

我已经尝试了多种不同的方法,使用带有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)

我正在使用Python3.8和discord.pyAPI的最新版本


Tags: 方法pyeventid消息示例messageasync
1条回答
网友
1楼 · 发布于 2024-10-16 20:45:54

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

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

为了锁定或取消锁定消息,bot还必须具有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")指定原因

文档:

相关问题 更多 >