如何使用 discord.py 中的图像编辑消息?

时间:2021-01-17 06:21:49

标签: python discord discord.py

我正在使用 discord.py 制作一个 discord 机器人,并想编辑我的机器人发送的文本消息,并将文本替换为图像。我尝试过的大多数事情都会给我一个错误,我在其他任何地方都找不到。

1 个答案:

答案 0 :(得分:1)

这是您用来编辑消息的示例。您必须将消息保存到变量中,然后您可以稍后对其进行编辑。查看下面的代码,要执行 ?test 命令并编辑该消息。

import asyncio
from discord.ext import commands

bot = commands.Bot(command_prefix="?", case_insensitive=True)

@bot.command()
async def test(ctx):
    message = await ctx.send("I'm message 1")
    await asyncio.sleep(5)
    await message.edit(content="I'm message 2")


bot.run(token)