So I've made a bot, but the command doesn't work, at least they don't get recognized. Any Ideas why?

const Discord = require('discord.js');
const token = 'token';
const { Client, GatewayIntentBits } = require('discord.js');
const client = new Client({
intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages],
});

function getQuote() {
return fetch("https://zenquotes.io/api/random")
.then(res => {
return res.json()
})
.then(data => {
return data[0]["q"] + " -" + data[0]["a"]
})
}


client.on('ready', () => {
console.log(`Zalogowano jako ${client.user.tag}`);
});

client.on('message', async (message) => {
if (message.content.startsWith('!addrole')) {
//mention == good, so does role menu == good
const user = message.mentions.user.first();
const role_name = message.content.split(' ').slice(2).join(' ');

if (!user || !role_name) {
console.log('dum didnt mention use haha or didnt prov a rol')
message.channel.send('pls mention user and prov a role name kthxbai')
return;
}


// check if rol exists alr
const role = message.guild.roles.cache.find((r) => r.name === role_name);

if (!role) {
console.log('alr found rol')
message.channel.send('alr is a role you dumb idiot')
}

//add role :D
const member = message.guild.members.cache.get(user.id);
if (member) {
member.roles.add(role)
.then (() =>{
console.log('add role ${role_name} to ${user.tag} hehe')
message.channel.send('meh add role ${role_name} to ${user.tag} hehe')
})
.catch((error) => {
console.error(error);
message.channel.send('oopsie~! ewwow cawwed whiwe abbing fe wowe');
})
}
}
})

client.on("message", msg => {
if (msg.author.bot) return

if (msg.content === "!inspire") {
console.log('inspring imagination - roblox')
getQuote().then(quote => msg.channel.send(quote))
}
})


client.login(token);
const Discord = require('discord.js');
const token = 'token';
const { Client, GatewayIntentBits } = require('discord.js');
const client = new Client({
intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages],
});

function getQuote() {
return fetch("https://zenquotes.io/api/random")
.then(res => {
return res.json()
})
.then(data => {
return data[0]["q"] + " -" + data[0]["a"]
})
}


client.on('ready', () => {
console.log(`Zalogowano jako ${client.user.tag}`);
});

client.on('message', async (message) => {
if (message.content.startsWith('!addrole')) {
//mention == good, so does role menu == good
const user = message.mentions.user.first();
const role_name = message.content.split(' ').slice(2).join(' ');

if (!user || !role_name) {
console.log('dum didnt mention use haha or didnt prov a rol')
message.channel.send('pls mention user and prov a role name kthxbai')
return;
}


// check if rol exists alr
const role = message.guild.roles.cache.find((r) => r.name === role_name);

if (!role) {
console.log('alr found rol')
message.channel.send('alr is a role you dumb idiot')
}

//add role :D
const member = message.guild.members.cache.get(user.id);
if (member) {
member.roles.add(role)
.then (() =>{
console.log('add role ${role_name} to ${user.tag} hehe')
message.channel.send('meh add role ${role_name} to ${user.tag} hehe')
})
.catch((error) => {
console.error(error);
message.channel.send('oopsie~! ewwow cawwed whiwe abbing fe wowe');
})
}
}
})

client.on("message", msg => {
if (msg.author.bot) return

if (msg.content === "!inspire") {
console.log('inspring imagination - roblox')
getQuote().then(quote => msg.channel.send(quote))
}
})


client.login(token);
15 Replies
d.js toolkit
d.js toolkitโ€ข8mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button! - โœ… Marked as resolved by OP
midawek
midawekโ€ข8mo ago
No description
Unknown User
Unknown Userโ€ข8mo ago
Message Not Public
Sign In & Join Server To View
midawek
midawekโ€ข8mo ago
- if (message.content.startsWith('!addrole'))
+ if (messageCreate.content.startsWith('!addrole'))
- if (message.content.startsWith('!addrole'))
+ if (messageCreate.content.startsWith('!addrole'))
Am I thinking right or not?
Unknown User
Unknown Userโ€ข8mo ago
Message Not Public
Sign In & Join Server To View
midawek
midawekโ€ข8mo ago
oh. Let me check if it works now Still nothing... Nothing even in the console
Unknown User
Unknown Userโ€ข8mo ago
Message Not Public
Sign In & Join Server To View
midawek
midawekโ€ข8mo ago
That's what I did before even I started coding but yeah
midawek
midawekโ€ข8mo ago
No description
Unknown User
Unknown Userโ€ข8mo ago
Message Not Public
Sign In & Join Server To View
midawek
midawekโ€ข8mo ago
It logs in and it doesn't seem to grab the messages Thonk
Unknown User
Unknown Userโ€ข8mo ago
Message Not Public
Sign In & Join Server To View
midawek
midawekโ€ข8mo ago
const Discord = require('discord.js');
const token = 'token';
const { Client, GatewayIntentBits } = require('discord.js');
const client = new Client({
intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages],
});

function getQuote() {
return fetch("https://zenquotes.io/api/random")
.then(res => {
return res.json()
})
.then(data => {
return data[0]["q"] + " -" + data[0]["a"]
})
}


client.on('ready', () => {
console.log(`Zalogowano jako ${client.user.tag}`);
});

client.on('messageCreate', async (message) => {
if (message.content.startsWith('!addrole')) {
//mention == good, so does role menu == good
const user = message.mentions.user.first();
const role_name = message.content.split(' ').slice(2).join(' ');

if (!user || !role_name) {
console.log('dum didnt mention use haha or didnt prov a rol')
message.channel.send('pls mention user and prov a role name kthxbai')
return;
}


// check if rol exists alr
const role = message.guild.roles.cache.find((r) => r.name === role_name);

if (!role) {
console.log('alr found rol')
message.channel.send('alr is a role you dumb idiot')
}

//add role :D
const member = message.guild.members.cache.get(user.id);
if (member) {
member.roles.add(role)
.then (() =>{
console.log('add role ${role_name} to ${user.tag} hehe')
message.channel.send('meh add role ${role_name} to ${user.tag} hehe')
})
.catch((error) => {
console.error(error);
message.channel.send('oopsie~! ewwow cawwed whiwe abbing fe wowe');
})
}
}
})

client.on('messageCreate', msg => {
if (msg.author.bot) return

if (msg.content === "!inspire") {
console.log('inspring imagination - roblox')
getQuote().then(quote => msg.channel.send(quote))
}
})


client.login(token);
const Discord = require('discord.js');
const token = 'token';
const { Client, GatewayIntentBits } = require('discord.js');
const client = new Client({
intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages],
});

function getQuote() {
return fetch("https://zenquotes.io/api/random")
.then(res => {
return res.json()
})
.then(data => {
return data[0]["q"] + " -" + data[0]["a"]
})
}


client.on('ready', () => {
console.log(`Zalogowano jako ${client.user.tag}`);
});

client.on('messageCreate', async (message) => {
if (message.content.startsWith('!addrole')) {
//mention == good, so does role menu == good
const user = message.mentions.user.first();
const role_name = message.content.split(' ').slice(2).join(' ');

if (!user || !role_name) {
console.log('dum didnt mention use haha or didnt prov a rol')
message.channel.send('pls mention user and prov a role name kthxbai')
return;
}


// check if rol exists alr
const role = message.guild.roles.cache.find((r) => r.name === role_name);

if (!role) {
console.log('alr found rol')
message.channel.send('alr is a role you dumb idiot')
}

//add role :D
const member = message.guild.members.cache.get(user.id);
if (member) {
member.roles.add(role)
.then (() =>{
console.log('add role ${role_name} to ${user.tag} hehe')
message.channel.send('meh add role ${role_name} to ${user.tag} hehe')
})
.catch((error) => {
console.error(error);
message.channel.send('oopsie~! ewwow cawwed whiwe abbing fe wowe');
})
}
}
})

client.on('messageCreate', msg => {
if (msg.author.bot) return

if (msg.content === "!inspire") {
console.log('inspring imagination - roblox')
getQuote().then(quote => msg.channel.send(quote))
}
})


client.login(token);
Unknown User
Unknown Userโ€ข8mo ago
Message Not Public
Sign In & Join Server To View
midawek
midawekโ€ข8mo ago
I just added to the intents GatewayIntentBits.MessageContent. I'll check if it works right now It works now! Thanks for the help @Jรด ๐ŸŒˆ๐ŸŽƒ๐Ÿฆ„๐Ÿ‘ป <a:AAE_Yippee:768160251077197904>