I am currently coding my first discord bot, it can already play YouTube music.
if (message.content.includes("Good Job") ||
message.content.includes("good job")) {
message.channel.sendMessage("Good Job everyone :smirk:");
}
As you see, if someone types "good job" (this is just an example) then the bot will reply with "good job everyone :smirk:), but then the spam will begin: the bot reads his own message and replies to it.
How can I prevent the bot from answering itself?
on('message', async msg => { // This block will prevent the bot from responding to itself and other bots if(msg. author. bot) { return } // Check if the message starts with '!
Because of the way Autocode automatically sets up Discord webhooks for you, each event our bot responds to will have a corresponding JavaScript file in your Autocode project: just like functions/events/discord/command. js .
Admins can add unique Discord bots to their servers. There are also powerful APIs for creating Discord bots for those who prefer to take matters into their own hands. For instance, Discord. js allows us to create a simple Discord bot using Javascript.
// In message event
if(message.author.id === client.user.id) return;
// I would recommend a variable like this for splits on words
// const args = message.content.trim().split(/\s+/g);
// You could also .slice() off a prefix if you have one
if(/good job/i.test(message.content)) {
message.channel.send('Good job everyone :smirk:'); // sendMessage is deprecated, use send instead
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With