I developed a bot. This is my code:
const Discord = require('discord.js')
const client = new Discord.Client()
client.on('ready', () => {
console.log(`Bot ready!`)
})
const filterNum = (str) => {
const numericalChar = new Set(["|","&","!","?",":","<","=",">","(",")","/","*","-","+",".","0","1","2","3","4","5","6","7","8","9"])
str = str.split("").filter(char => numericalChar.has(char)).join("");
return str;
}
client.on('message',(msg)=>{
user = msg.author
msg1 = msg.content
msg1 = msg1.toLowerCase()
msg1 = msg1.replace(new RegExp(/[àáâãäå]/g),"a")
msg1 = msg1.replace(new RegExp(/[èéêë]/g),"e")
msg1 = msg1.replace(new RegExp(/[ìíîï]/g),"i")
msg1 = msg1.replace(new RegExp(/[òóôõö]/g),"o")
msg1 = msg1.replace(new RegExp(/[ùúûü]/g),"u")
msg1 = msg1.replace(new RegExp(/[ýÿ]/g),"y")
try{
if(msg.content.startsWith("/kick")){
if(user.hasPermission(['KICK_MEMBERS', 'BAN_MEMBERS'])){
member = msg.mentions.members.first()
if(member.hasPermission(['KICK_MEMBERS', 'BAN_MEMBERS'])){
msg.channel.send("No se puede kickear a un staff.")
}else{
member.kick().then((member) => {
msg.channel.send("Kickeado exitosamente.")
}).catch(() => {
msg.channel.send("Acceso denegado.")
})
}
}else{
msg.channel.send("/kick "+user)
}
}
}catch(e){
msg.channel.send(e.message)
}
if(msg.content.startsWith("/calc")){
try{
operation=msg.content.split("/calc")[1]
operation=filterNum(operation)
result=eval(operation)
msg.channel.send("```"+operation+"≡"+result+"```")
}catch(e){
msg.channel.send(e.message)
}
}
if(!msg.content.startsWith("/calc")&&!msg.content.startsWith("/kick")&&msg.content.startsWith("/")){
msg.reply(`
Comando desconocido. Aquí tienes la lista de comandos:
/kick miembro: Expulsa a un miembro de la sala.
/calc operación: Calcula una operación matemática.
`)
}
})
client.login('token')
And this is the error:
user.hasPermission is not a function
I tried to change it to another command and it didn't worked. I tried to show msg.author, and it's undefined, but strangely, msg.author.bot is defined as a boolean. It's weird. Looks like a problem with discord.js
API. I cant show the token because someone can utilize my bot into his purposes, but, anywhere.
What can I do? Thanks for helping.