首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何让Commando机器人响应消息中任意位置包含某个子字符串的消息

如何让Commando机器人响应消息中任意位置包含某个子字符串的消息
EN

Stack Overflow用户
提问于 2019-08-11 03:18:15
回答 1查看 680关注 0票数 2

我正在与一位朋友合作,为现有的Discord机器人添加一些东西。有许多有效的命令使用了discord.js-commando,所以我们只能使用特种部队。

我们这样做的行业协会已经将一些资源从旧网站转移到新网站,我们想提醒链接到旧网站的行业协会成员,他们应该使用新网站:

代码语言:javascript
复制
// 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时才会触发。

这是代码。

代码语言:javascript
复制
// file: index.js
const bot = new Commando.Client({
    commandPrefix: './'
});

bot.registry
    .registerGroup('autoresponses', 'AutoResponses')
    // other groups
    .registerDefaults()
    .registerCommandsIn(__dirname + '/commands')
    ;

我正在处理的文件

代码语言:javascript
复制
// 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。用特种部队能做到这一点吗?或者我需要另一种方法?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-08-11 04:00:31

如果您打算使用Comando,则需要使用Commando.Client。设置机器人的方法是,您只需在commands文件夹中添加一个命令。似乎Comando有一种在正则表达式上触发的方法。

代码语言:javascript
复制
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 (您的命令配置)的文档。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57445034

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档