javascript - 带有 Javascript 的 Discordbot 没有反应
问题描述
我目前正在学习使用 node.js 编写 discordbots。出于某种原因,机器人会上线,但不会对我编码的命令做出反应。为了测试原因,我什至从教程中获取了解决方案,但仍然是同样的问题。有人知道解决方案吗?
const client = new Discord.Client();
const prefix = '-';
client.once('ready', () => {
console.log('BOT ist online');
});
client.on('Message', (message) => {
if(!message.content.startsWith(prefix) || message.author.bot) return;
const args = message.content.slice(prefix.length).split(/ +/);
const command = args.shift().toLowerCase();
if(command === 'ping'){
message.channel.send('pong!');}
else if(command == 'youtube'){
message.channel.send('TEST');}
});
client.login('Here goes the token');
解决方案
这是一个小修复,所以如果可以的话,我会发表评论,但我还不能。
你在哪里:
client.on('Message', …)
它应该是这样的消息上的小写“m”:
client.on('message', msg => {
if (msg.content === 'ping') {
msg.reply('Pong!');
}
});
推荐阅读
- r - 在R中使用for循环替换列的平均值
- c# - SOAP HTTPS 服务在 c# 中使用
- android - Room SQLite 文件 - 确保所有更改都已刷新,并且在文件上传过程中没有 I/O
- sql - SSRS 参数删除其他过滤器
- logstash - 解析 nginx 错误日志的 grok 模式的问题
- php - 如何使用 PHP 将月份添加到特定日期?
- intel - 错误:无法安全地从此类存储库进行更新,因此默认禁用
- javascript - 未捕获的 URIError:尝试解码 var 时 URI 格式错误(javascript)
- c# - 当 RowState = Modified 时 SQLDataAdapter.Update() 不更新
- python - 命名两个或多个相关 Python 变量的首选方法是什么?