【发布时间】:2019-04-11 12:03:29
【问题描述】:
您好,我刚刚开始创建一个不和谐的机器人。我有代码,是我从在线教程中复制的,当我在我的不和谐服务器上的任何地方输入!play 时,它会有一个机器人说"@everyone We are playing! :)"。
我希望它以某种方式工作,以便当我在机器人频道中输入 !play 时,它会向 looking-for-game channel 发送消息。我将粘贴我的整个代码,但我认为重要的部分是:
bot.sendMessage({
to: channelID,
message: '@everyone The Owner, Admins and The OGs are playing Mass Effect Andromeda! Come play with them! :smiley:'
});
有没有办法让它发送到特定频道而不是channelID?
如果解决方案需要,这是整个代码。
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) {
// !play
case 'play':
bot.sendMessage({
to: channelID,
message: '@everyone The Owner, Admins and The OGs are playing Mass Effect Andromeda! Come play with them! :smiley:'
});
break;
// Just add any case commands if you want to..
}
}
});
【问题讨论】:
标签: javascript discord discord.io