我有以下代码:
bot.on('message', msg =>{
if(msg.content === "Hello"){
const hello1 = 'Hello mah boi! or girl... eh'
const hello2 = 'Sup.'
const hello3 = 'Wassup?'
const hello4 = 'HEEEEEELLLLOOOOO BOOOOOIII'
const hello5 = 'Are you sure you wanna say hi??'
const hello6 = '.'
const hello7 = 'Heeeeeyyyyyyyyy ey eyyyyyyyy'
const items = [
hello1,
hello2,
hello3,
hello4,
hello5,
hello6,
hello7
];
const rndString = items[Math.floor(Math.random() * items.length)];
msg.channel.send(rndString);
}
})
我正在尝试创建一个随机消息命令,但它不起作用。没有消息被发送。它也不会抛出任何错误。
答案 0 :(得分:0)
我做同样的事情,除了模因。你可以试试这个,这是我的代码:
const memes = [
'https://tenor.com/LxdC.gif',
'https://tenor.com/Fm1D.gif',
'https://tenor.com/bqltH.gif',
'https://tenor.com/4nHj.gif',
'https://tenor.com/zFEB.gif',
'https://tenor.com/xa3U.gif',
'https://tenor.com/wMSx.gif',
'https://tenor.com/HxIT.gif',
'https://tenor.com/XGES.gif',
'https://tenor.com/bdnvi.gif',
'https://tenor.com/yf4L.gif',
'https://tenor.com/bnU5s.gif',
'https://tenor.com/xjhw.gif',
'https://tenor.com/2Rbt.gif',
'https://tenor.com/bE4YO.gif',
'https://tenor.com/bEOYD.gif'
]
client.on('message', (message) => {
if (message.content.startsWith('!memes')) {
const response = memes[Math.floor(Math.random() * memes.length)];
message.channel.send(response);
}
});
client.on('message', (message) => {
if (message.content.startsWith('!memesdm')) {
const response = memes[Math.floor(Math.random() * memes.length)];
message.author.send(response);
}
});
如果这对您有帮助,请您点击此帖子旁边的绿色对勾以便我知道吗?
答案 1 :(得分:-3)
你可以这样做:
bot.on('message', msg =>{
if(msg.content === "Hello"){
function random() {
const hello1 = 'Hello mah boi! or girl... eh'
const hello2 = 'Sup.'
const hello3 = 'Wassup?'
const hello4 = 'HEEEEEELLLLOOOOO BOOOOOIII'
const hello5 = 'Are you sure you wanna say hi??'
const hello6 = '.'
const hello7 = 'Heeeeeyyyyyyyyy ey eyyyyyyyy'
var rand = [hello1, hello2, hello3, hello4, hello5, hello6, hello7];
return rand[Math.floor(Math.random()*rand.length)];
}
message.channel.send(random())
}
})