如何在Python Discord Bot(重写)中获得用户输入



我在Python 3.8.5上制作了一个discordbot。我正在通过正确的语法和命令打印此菜单。现在,我希望用户根据要选择的选项键入数字1或2。这是我的代码:

async def menu(self, ctx):
await ctx.message.delete()
embed = discord.Embed(
title = "Heartbeat Menu",
description = "Select and enter a number.n 1. Check Status of Heartbeatn 2. Hearbeat Check"
)
sent = await ctx.send(embed=embed)

它工作正常。应该编写哪些代码,当用户键入1或2时,机器人会识别并打印其他内容。

@client.command()
async def menu(ctx):
await ctx.message.delete()
embed = discord.Embed(
title = "Heartbeat Menu",
description = "Select and enter a number.n 1. Check Status of Heartbeatn 2. Hearbeat Check"
)
sent = await ctx.send(embed=embed)

def check(msg):
return msg.author == ctx.author and msg.channel == ctx.channel and msg.content in ["1", "2"]
msg = await client.wait_for("message", check=check)
if msg.content == "1":
#code for number 1
else:
#code for number 2

我使用client.wait_fo方法等待用户输入,menu函数中的check()函数将检查是否有正确的user , channel , message is 1/2,如果满足,则执行#code for number 1#code for number 2!如果你仍然难以理解,我建议你阅读这份文件!

最新更新