我正在尝试向机器人进行第二次输入

时间:2020-07-25 21:18:54

标签: discord.js

我正在尝试在您输入命令的地方发出命令,并且机器人说:确定吗?然后,您输入是或否,但是我不知道该如何做,以便用户可以回复。有人可以帮忙吗?

1 个答案:

答案 0 :(得分:1)

有一些方法可以做到这一点,使用MessageCollector收集用户响应更加容易。 示例:

message.channel.send("Are you sure?")

const filter = (m) => m.author.id === message.author.id && (m.content.toLowerCase() === "yes" || m.content.toLowerCase() === "no")  // Create a filter, only accept messages from the user that used the command and the message includes "yes" or "no"
message.channel.awaitMessages(filter, {max: 1, time: 30000})
    .then(collected => {
        const msg = collected.first()
        if(msg.content.toLowerCase() === "yes") {
            // User sent yes
        } else {
            // User sent "no"
        }
    })

您也可以使用TextChannel.awaitMessages,它返回带有消息的Promise。 示例:

module.exports = {
    GetRandomNum:(Min,Max)=>{
        var Range = Max - Min;   
        var Rand = Math.random();   
        return(Min + Math.round(Rand * Range)); 
    },
    mathCalculationtion:()=>{
        var firstPlace = this.GetRandomNum(1, 9);
        return firstPlace;
    }
}