我正在与一位朋友合作,为现有的Discord机器人添加一些东西。有许多有效的命令使用了discord.js-commando,所以我们只能使用特种部队。
我们这样做的行业协会已经将一些资源从旧网站转移到新网站,我们想提醒链接到旧网站的行业协会成员,他们应该使用新网站:
// User123 says...
Check out https://www.example.com/.
// bot responds:
Hey User123! You should use our new site! https://www.example2.com/机器人只有在看到www.example.com时才会触发。
这是代码。
// file: index.js
const bot = new Commando.Client({
commandPrefix: './'
});
bot.registry
.registerGroup('autoresponses', 'AutoResponses')
// other groups
.registerDefaults()
.registerCommandsIn(__dirname + '/commands')
;我正在处理的文件
// file: commands/autoresponses/messages.js
const discord = require('discord.js');
client.on("message", function(message) {
if (message.author.bot) {
return;
}
if (message.content.includes("www.example.com")) {
var responseString = "Hey " + message.author + "! That's the old site! Please use the new one: https://www.example2.com/";
message.channel.send(responseString);
}
};问题是,这不是使用特种兵,而是普通的discord.js。用特种部队能做到这一点吗?或者我需要另一种方法?
发布于 2019-08-11 04:00:31
如果您打算使用Comando,则需要使用Commando.Client。设置机器人的方法是,您只需在commands文件夹中添加一个命令。似乎Comando有一种在正则表达式上触发的方法。
let Command = require('Comando').client;
module.exports = class OldWebsite extends Command {
constructor(client){
super(client, {/* Your command config here */, patterns: [/website\.com/] });
//patterns is a prop that accepts regular expressions to match on a message
}
async run(msg){
return msg.reply('Hey that\'s our old webiste!');
}
}这是一个Command的例子。下面是可以进入CommandInfo (您的命令配置)的文档。
https://stackoverflow.com/questions/57445034
复制相似问题