简体   繁体   中英

discord.py - Updating Specific Messages

I wanted my bot to edit an message every 5 minutes.

For example

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

Do you mean something like this?


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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM