尝试在不重启机器人的情况下执行随机命令
2021-06-17
81
我试图关注此链接: 随机消息回复 Discord.js 2020
但在尝试实现它时遇到了困难。基本上,使用 discord.js 库,我有一个频道,我想允许一个单词和一个单词。当有人在该频道中发布任何不是该单词的内容时,我希望机器人删除它并从数组中随机挑选一个回复。我已经让它随机选择一个索引项,但它并没有真正保持随机。回复唯一会改变的时候是机器人重新启动时。我希望它在每次事件发生后执行,但每次我尝试时,我都会得到 ReferenceError:execute 未定义。
今天是我使用 Javascript 的第一天,所以任何简化它的方法都将不胜感激。我反复测试过,它运行良好,直到我尝试使用执行函数。我使用 Visual Code Studio 进行编码,使用 node.js 运行文件。
除了 discord.js、dotenv 和 nodemon 之外,我没有导入任何其他文件。我不知道执行应该做什么。我只是盲目地点击链接。
这是我的代码:
const client = new Client();
const bredfreply = [
'Excuse me person. I see you are participating in the "bredf" channel in the INCREDIBLE Realm of Eden. Unfortunately, this channel is only limited to bredf. I cannot believe you would speak any other word. You should be ashamed!',
'Did you do what I think you just did? EXCUSE ME, but bredf is only for bredf. You MUST say bredf because it is bredf and everyone knows bredf is only bredf and not whatever you thought it was. bredf. Only bredf.',
'You person, are in trouble. For the fact that you are rebelling against the bredf, you have lost one cookie. I do not care if you already did not have cookie because now you have less than no cookies. You actually OWE cookies so pay up.',
'Whatever you just did? That was not bredf.',
'bredf bredf bredf bredf bredf bredf bredf bredf bredf bredf bredf bredf',
'PLEASE only post bredf in the channel. You are scaring the other bredfs.',
'Did you hear about bredf? It is this really cool thing that all the cool kids post in bredf. Oh, you must not be bredf because I do not see you in there. You should be bredf.',
'*sniffles* I want bredf. Can you help me? Put it in the channel then because I do not think you can.',
'I only like people that say bredf. Since you apparently are not, that must mean I do not like you. Hmph'
];
client.on('ready', () => {
console.log(`${client.user.username} is ready to start the day!`);
});
client.on('message', (message) => {
if(message.channel.id == '840422367829164052' && message.content != 'bredf'
&& message.author.id != '854877244157853716')
execute(message,)
const randombredfreply = bredfreply[Math.floor(Math.random(1)) * bredfreply.length];
message.author.send(randombredfreply);
message.delete()
}
)```
2个回答
您是否从任何其他文件导入了
execute
函数?或者
execute
函数有什么作用?
Anil Kumar
2021-06-17
我通过尝试解决了这个问题。我通过将我的
通过移动我的
var randombredfreply = bredfreply[Math.floor(Math.random() * bredfreply.length]);
移动到我的 if(... 命令) 中,只要满足 if 参数,它就会重新计算。
这是最终代码:
if(message.channel.id == '840422367829164052' && message.content != 'bredf'
&& message.author.id != '854877244157853716')
{
var randombredfreply = bredfreply[Math.floor(Math.random() * bredfreply.length)];
message.author.send(randombredfreply);
message.delete()
}
})
Thrall of Eden
2021-06-17