python - discord.py - 更新特定消息
问题描述
我希望我的机器人每 5 分钟编辑一次消息。
例如
msg = discord.utils.get(message, "edited")
cliend.edit_message(message, msg)
解决方案
你的意思是这样的吗?
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)
推荐阅读
- sql - 有没有办法更新证书而无需更改 SQL Server 配置管理器中的证书(的指纹)?
- prolog - 执行所有子句并删除一些子句
- java - art::OatHeader::IsDebuggable() const 崩溃,Android 11,Google Ads SDK 19.7.0
- python - 遍历 CSV 时跳过 For 循环
- java - Docker Image 和 Java HTTP Post 请求
- python-3.x - 熊猫计算重复条目
- python - pygame.key.get_pressed() 和 event.type 有什么区别?
- javascript - 未捕获的 TypeError:timer.getTime 不是更新时的函数
- r - Revealjs中的R传单
- typescript - 如何在 Deno 中制作图形应用程序?