[英]How does my discord bot react to messages outside the / command
Let's take a quiz as an example, the user makes the command "/quiz rules" to start a quiz about the rules.让我们以一个小测验为例,用户发出命令“/quiz rules”来开始一个关于规则的小测验。 How do I then make the bot accept the user's next messages as answers?
然后我如何让机器人接受用户的下一条消息作为答案?
Python - nextcord Python - 下线
@client.slash_command(guild_ids=[testing_id])
async def quiz(interaction: Interaction,
value: str = SlashOption(
name="value",
choices=["rules"]
)):
Thank you谢谢
So you'll want to add a client event listener and do something when the on_message
event fires.因此,您需要添加一个客户端事件侦听器并在
on_message
事件触发时执行一些操作。
@client.event
async def on_message(message):
# do something with the message here
So for your quiz example;因此,对于您的测验示例; you'd have to keep track of when a quiz has started, which channel it's in, and which user initiated it (provided you only want a particular user answering) and then parse the message to see if it's an answer to the question it was asked.
你必须跟踪测验何时开始,它在哪个频道,哪个用户发起它(前提是你只希望特定用户回答)然后解析消息以查看它是否是问题的答案问。 But using
on_message
is what I would do.但是使用
on_message
是我会做的。
You could also use the wait_for
method to wait for a message from a particular user as well.您也可以使用
wait_for
方法来等待来自特定用户的消息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.