你好,我刚开始创建一个不和谐的机器人。我有从在线教程中复制的代码,当我在任何地方的不和谐服务器上输入!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..
}
}
});
答案 0 :(得分:2)
您必须获取行会对象,并从中获取通道对象,然后向该对象发送消息。
class SubPage extends StatefulWidget {
SubPage({Key key, this.child}) : super(key: key);
final Widget child;
@override
SubPageState createState() => new SubPageState();
}
class SubPageState extends State<SubPage> {
@override
Widget build(BuildContext context) {
return widget.child;
}
}
,您可以执行bot.on("message")
如果在!command上将其发送到特定频道,则可以执行message.channel.send("Message")
您也可以执行message.guild.channel.get("CHANNEL-ID").send("Message");
,尽管通常不这样做,但最好通过ID查找
message.guild.channel.find("name", "channel-name").send("Message");