Reputation:
This is my code:
const Discord = require('discord.js');
const {Client, Attachment} = require('discord.js');
const bot = new Client();
const PREFIX = 'z';
bot.on('message', message => {
let args = message.content.substring(PREFIX.length).split(" ");
switch(args[0]){
case 'general':
const general = new Discord.MessageEmbed()
.setTitle('**𝙎𝙚𝙩𝙩𝙞𝙣𝙜𝙨**')
.setThumbnail('https://media.discordapp.net/attachments/716968826129874984/720196083858276362/3.gif')
.setFooter('General Commands...should be straight foward!!!')
.addField('**𝙂𝙚𝙣𝙚𝙧𝙖𝙡** ', ' `prefix | profile | bot info | about | avi` ')
.setFooter('put "z" behind of each word to open more commands...')
.setColor(0xFF0000)
.setFooter('Made by 11 | discord.gg/PPNyDyw');
message.channel.send(general);
break;
The prefix is "z", but if i was to type "ngeneral" or put any letter before the command the bot would respond with the command.
How do I fix this?
Upvotes: 1
Views: 118
Reputation: 230
You need to check if the message starts with the prefix. We can use the startsWith() method for this.
if (message.content.startsWith(prefix) {...}
else {...}
Upvotes: 1