owengombas / discord.ts

🤖 Create your discord bot by using TypeScript and decorators!
https://owencalvin.github.io/discord.ts/
325 stars 40 forks source link

[FEATURE] Option to mention bot #32

Closed IcyTv closed 3 years ago

IcyTv commented 3 years ago

Hi, I would love to have a feature, where you can mention the bot (i,e, \@ Bot help) and avoiding the prefix. I have tried to implement this using Guards or Rules and it simply does not work. I know you can implement this in the on("Message") handler, but then you lose all modularity of the command/event structure, as you cannot forward or close.

IcyTv commented 3 years ago

I figured it out. For everyone wondering:

const prefixBehavior = async (message: Message, client: Client) => {
    if(message.mentions.has(message.client.user.id)) {
        console.log(message.content.match(/<@.*>/)[0]);
        return message.content.match(/<@.*>/)[0] + " ";
    }
    return prefix;
}

@Discord(prefixBehavior, {