我已经尝试了多种不同的方法来固定(我也想试着取消固定它)某个消息(它已经被发送了),使用discord.py的机器人/自我机器人,这里有几个例子:
@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.py API。
发布于 2021-07-02 14:14:23
为了固定一条消息,你必须首先有消息,一旦你有它,你可以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")指定原因
文档:
发布于 2022-02-05 13:50:56
对于固定消息,您可以使用:
await message.pin(reason=None)用于解除锁定:
await message.unpin(reason=None)从您的示例中可以看出:
@client.event
async def on_message(message):
if message.content == 'message im trying to pin':
await message.pin()更多信息,请访问接口:https://docs.pycord.dev/en/master/api.html?highlight=pin#discord.Message.pin。
请注意,机器人需要Manage Messages来执行此操作。
https://stackoverflow.com/questions/68219913
复制相似问题