【发布时间】:2019-06-07 22:53:08
【问题描述】:
我已经创建了令牌、权限和授权正确的服务器
代码
var Discord = require('discord.io');
var logger = require('winston');
var auth = require('./auth.json');
// Configure logger settings
logger.remove(logger.transports.Console);
logger.add(new logger.transports.Console, {
colorize: true
});
logger.level = 'debug';
// Initialize Discord Bot
var bot = new Discord.Client({
token: auth.token,
autorun: true
});
bot.on('ready', function (evt) {
logger.info('Connected');
logger.info('Logged in as: ');
logger.info(bot.username + ' - (' + bot.id + ')');
});
bot.on('message', function (user, userID, channelID, message, evt) {
// Our bot needs to know if it will execute a command
// It will listen for messages that will start with `!`
if (message.substring(0, 1) == '!') {
var args = message.substring(1).split(' ');
var cmd = args[0];
args = args.splice(1);
switch(cmd) {
// !ping
case 'ping':
bot.sendMessage({
to: channelID,
message: 'Pong'
});
break;
// Just add any case commands if you want to..
}
}
});
bot.on('message', function (user, userID, channelID, message, evt) {
// Our bot needs to know if it will execute a command
// It will listen for messages that will start with `!`
if (message.substring(0, 1) == '!') {
var args = message.substring(1).split(' ');
var cmd = args[0];
args = args.splice(1);
switch(cmd) {
// !ping
case 'img':
bot.sendMessage("img", {
file: "https://i.imgur.com/hIK7JKq.jpg" // Or replace with FileOptions object
});
break;
// Just add any case commands if you want to..
}
}
});
// I've tried with this Perm Int : 522304
重启我的服务器
我测试过
我没有看到任何发送的图像。
如何进一步调试?
【问题讨论】:
-
bot.on('message'被触发了吗? -
是的,它触发了。
-
我试过
!ping,我得到了"pong" -
为什么你有两个“消息”监听器?这对我来说没有多大意义,其中一个可能不会触发。
-
我听了 2 次,因为当我添加另一个案例时出现了一些问题,第二个案例不断触发。
标签: javascript node.js discord discord.io