【问题标题】:How to edit embed with message id discord bot py in on_ready event如何在 on_ready 事件中使用消息 id discord bot py 编辑嵌入
【发布时间】:2021-09-29 16:04:51
【问题描述】:

我想编辑 on_ready 事件中的嵌入,这是我可以编辑的唯一方法可以执行 on_message 还是有办法让函数保持运行直到程序结束?

from discord.ext import commands
import discord
from discord.utils import get

@bot.event
async def on_ready():
    msg = bot.get_message(892788147287654471)
    em = discord.Embed(title="lik",description="kjk")
    await msg.edit(embed=em)

bot.run(os.environ['token'])

错误代码:

Ignoring exception in on_ready
Traceback (most recent call last):
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/client.py", line 343, in _run_event
    await coro(*args, **kwargs)
  File "main.py", line 56, in on_ready
    msg = bot.get_message(892788147287654471)
AttributeError: 'Bot' object has no attribute 'get_message'

【问题讨论】:

    标签: python-3.x discord.py


    【解决方案1】:

    正如错误所说,机器人没有get_message 属性。相反,您可以做的是获取频道,然后获取其中的消息或部分消息。

    https://discordpy.readthedocs.io/en/master/api.html?highlight=partial%20message#discord.PartialMessage

    例子:

    message = bot.get_channel(1234567890).get_partial_message(1234567890)
    await message.edit(content="test")
    

    【讨论】:

    • 谢谢....我会检查一下
    • 完美运行。
    猜你喜欢
    • 2021-05-04
    • 2021-12-12
    • 2022-01-05
    • 2021-08-12
    • 2021-03-23
    • 1970-01-01
    • 2022-01-20
    • 1970-01-01
    • 2021-06-17
    相关资源
    最近更新 更多