+
Skip to content

Conditional commands with regex #200

@Ahmadh26

Description

@Ahmadh26

i'm trying to make an autoresponse with my bot and trying to use conditional commands to know whether the command is enabled or disabled. here is the code that i have for it:

const { Command } = require('discord-akairo');
const typeorm = require('typeorm');

class ReeCommand extends Command {
	constructor() {
		super('ree', {
			regex: /^ree+$/i,
			typing: true,
			cooldown: 25000,
		});
	}
	async condition(message) {
		const connection = typeorm.getConnection();
		const getStatus = await connection.query(`SELECT status FROM autores WHERE ar = "ree" AND channel = "${message.channel.id}"`);
		// if(getStatus.length < 1) {
		// 	connection.query(`INSERT INTO autores (ar, status, channel) VALUES ("ree", "1", "${message.channel.id}")`);
		// }
		return await getStatus[0]['status'] === 1;
	}
	async exec(message) {

			return message.util.send(`${message.content.toUpperCase()}E`);

	}
}

module.exports = ReeCommand;

the bot responds to the message whether the trigger is enabled or not, i use a MySQL database where i have a status set to either 0 or 1 per channel to know if it's enabled there or no.

i have tried using aliases rather than regex and it worked fine, the issue is only happening with regex :/
the bot also edits the message for some unknown reason. there is a Gif attached.

dfw8D9tLMC

what could cause this? Am i doing something wrong?
thanks for the help

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载