'message.content.startsWith is not a function error
here is my code
const prefix = '!';
module.exports = {
name: 'messageCreate',
once: false,
execute(client, message) {
if (message.author.bot) return;
if (!message.content.startWith(prefix)) return;
const args = message.content.slice(prefix.length).trim().split(/ +/g);
const cmdName = args.shift().toLowerCase()
if (cmdName.length == 0) return;
let cmd = client.commands.get(cmdName)
if (cmd) cmd.run(client, message, args)
}
}
It gives me this error: TypeError: message.content.startswith is not a function
What is the solution to this problem?
Solution 1:[1]
According to your code:
const prefix = '!';
module.exports = {
name: 'messageCreate',
once: false,
execute(client, message) {
if (message.author.bot) return;
if (!message.content.startWith(prefix)) return;
// the above line should read as below
const args = message.content.slice(prefix.length).trim().split(/ +/g);
const cmdName = args.shift().toLowerCase()
if (cmdName.length == 0) return;
let cmd = client.commands.get(cmdName)
if (cmd) cmd.run(client, message, args)
}
}
the function is startsWith, not startWith
if (!message.content.startsWith(prefix)) return;
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Gh0st |