我正在尝试用一个不和谐的机器人制作一个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.
}
}
})不确定用户将如何插入变量...有人知道怎么做吗?
发布于 2020-06-28 13:58:05
你需要弄清楚如何让你的机器人具有交互性。它可以发送像“给我一个动词”这样的消息,然后从聊天中的命令中获取响应。我不知道如何针对不一致做这件事,所以你需要做一些关于如何从用户那里获得响应的进一步研究。
发布于 2020-06-28 18:49:04
您可以简单地使用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
https://stackoverflow.com/questions/62618764
复制相似问题