python - Discord.py 消息固定?

标签 python discord discord.py python-3.8

我尝试了多种不同的方法来使用带有discord.py的机器人/ self 机器人来固定(我也想尝试取消固定)特定消息(它已经发送),这里有一些示例:

@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。

最佳答案

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

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

机器人还必须拥有 manage_messages 权限才能固定或取消固定消息。

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

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

如果您想固定特定消息,则必须使用 ctx.fetch_message(message_id) 获取它,或者如果您有文本 channel 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") 指定原因

文档:

关于python - Discord.py 消息固定?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68219913/

相关文章:

python - 使用 pandas 时 Discord.gateway 警告 "Shard ID None heartbeat blocked for more than 10 seconds."

python - 基于 stomp.py 的持久客户端填充 ActiveMQ 中的订阅者列表

Python - 使用带通配符的 str.replace

javascript - 如果 GuildID 未在我的代码中列入白名单,如何让我的 Discord.js (Commando) 机器人离开服务器(加入时)?

python - 运行机器人示例代码时,出现此错误

python - 每个服务器前缀

python - 从嵌入的消息中获取内容?

python - 预测单个时隙的位置点集

python - 高效获取正方形线上的格点

python - 如何使用新的 Discord.py 版本获取 Discord 服务器中所有成员的列表?