0

我试图用一个不和谐的机器人制作一个 madlib,不知何故我必须为用户消息的每一行分配一个变量......

到目前为止,这是我的代码:

client.on('message', message=>{//madlib
    var lib1 = [
        ' ',//<--(X)
        'VERB',
        'ADJECTIVE',
        'NOUN (PLURAL)',
        'ADJECTIVE',
        'VERB ENDING IN "ING"',
        'VERB',
        'NUMBER',
        'ADJECTIVE',
        'NOUN (PLURAL)',
        'NOUN (PLURAL)',
        'NOUN (PLURAL)',
        'RELATIVE (PLURAL)',
        'ADJECTIVE',
        'ADJECTIVE',
        'NOUN (PLURAL)',
    ]
    
    
    if (message.content == '!madlib'){
        var rand = Math.floor(Math.random() * 2) + 1;
        if (rand == '1'){
            message.reply(lib1);
        }
        if (rand == '2'){
            //im gonna put another madlib right here as another option and more random options.
        }
    }

})

不确定用户将如何插入变量...有人知道怎么做吗?

4

2 回答 2

0

您可以简单地使用message.channel.awaitMessages()来等待用户的响应。

这是一个例子:

message.reply("Send a message!! (expires in 10s)")
const filter = m => m.autor.id === message.author.id;
message.channel.awaitMessages(filter, {
   max: 1,
   time: 10_000,//(10 seconds)
   errors: ['time']
})
  .then(async(msgs) => {
    //msgs is a collection. You need to do msgs.first() to get the first message
     const msg = msgs.first();
      //now just use "msg" as your normal message variable, like so
          message.reply("I have received your message: " + msg.content)
})
  .catch(() => message.reply("You took too long"))

另请参阅https://discordjs.guide/popular-topics/collectors.html#await-messages

于 2020-06-28T10:49:04.497 回答
0

您需要弄清楚如何使您的机器人具有交互性。它可以发送诸如“给我一个动词”之类的消息,然后从聊天中的命令中获取响应。我不知道如何专门为 Discord 执行此操作,因此您需要进一步研究如何获得用户的响应。

于 2020-06-28T05:58:05.353 回答