【问题标题】:Discord.py message pinning?Discord.py 消息固定?
【发布时间】:2021-09-14 02:19:24
【问题描述】:

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

【问题讨论】:

    标签: python discord discord.py python-3.8


    【解决方案1】:

    要固定消息,您必须先拥有该消息,一旦拥有该消息,您就可以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") 指定原因

    文档:

    【讨论】:

    • 请对照标签检查您的链接。我让它们保持一致,但你可能想要其他东西。
    • 我一直在寻找它具有 on_connect 功能,而不是由命令激活,抱歉我提供的信息不足,例如;我会启动机器人,它会固定一条消息,例如“我在线”
    【解决方案2】:

    对于固定消息,您可以使用:

    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()
    

    转到 API:https://docs.pycord.dev/en/master/api.html?highlight=pin#discord.Message.pin 了解更多信息。

    请注意,机器人需要管理消息来执行此操作。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-06-29
      • 1970-01-01
      • 2019-06-02
      • 2021-05-17
      相关资源
      最近更新 更多