首页 > 解决方案 > discord.py - 更新特定消息

问题描述

我希望我的机器人每 5 分钟编辑一次消息。

例如

msg = discord.utils.get(message, "edited")
cliend.edit_message(message, msg)

标签: pythondiscord.py

解决方案


你的意思是这样的吗?


bot=commands.Bot(command_prefix='.')

messages=[]
async def edit_msg():
    num=0
    while True:
        if messages:
            for i in messages:
                await bot.edit_message(i,new_content=f'This is message {num}')
                num+=1
        await asyncio.sleep(300)


@bot.event
async def on_ready():
    await edit_msg()
    print(f"{bot.user.name} is ready to run!")


@bot.command(pass_context=True)
async def edit_me(con,*,message):
    msg=await bot.say(message)
    messages.append(msg)


@bot.command(pass_context=True)
async def edit_emb(msg):
    emb=discord.Embed(title='Title Embed')
    emb.add_field(name='name of the embed',value='value for field')
    reply=await bot.say(embed=emb)
    await asyncio.sleep(3)

    new_embed=discord.Embed(title='New embed')
    new_embed.add_field(name='new emb',value='the new value')
    await bot.edit_message(reply,embed=new_embed)


推荐阅读