python - 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。
解决方案
为了固定消息,您必须首先拥有该消息,一旦您拥有它,您就可以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")
文档:
推荐阅读
- json - 如何在飞镖中打印 JSON?
- javascript - 如何在 HomeScreen 等屏幕之间导航数据到 AddtoCart 屏幕并在 Hooks 中添加数据
- r - 使用仪表板中的下拉菜单切换报告时出现未知列错误
- javascript - 对值的空值检查在 Javascript 中不起作用
- javascript - 如何为仅有条件定义的对象强制 IntelliSense?
- python - 如何使用python(BeautifulSoup)从代码中提取以下src(iframe)
- r - 从开始/结束坐标创建折线并组合属性数据
- javascript - 从函数参数中获取解构对象作为单个对象
- python - 尝试使用python在mysql上异步调用存储过程,无法这样做
- python - Python 生成错误的字典哈希