My bot isnt responding to any of my commands can you look to see where I went wrong? I think it might be the intents but I am not sure. I followed the discord guide and some posts on here to just have all intents declared. Do I need to list them individually or does my current way work?
require('dotenv').config();
const Discord = require('discord.js');
const sqlite3 = require('sqlite3').verbose();
const { Client, GatewayIntentBits } = require("discord.js");
const client = new Client({
intents: Object.keys(GatewayIntentBits).map((a)=>{
return GatewayIntentBits[a]
}),
});
const prefix = "!";
let db = new sqlite3.Database('./keywords.db', (err) => {
if (err) {
return console.error(err.message);
}
console.log('Connected to the SQlite database.');
db.run(`CREATE TABLE IF NOT EXISTS keywords (
keyword TEXT,
channelOrCategory TEXT,
role TEXT,
author TEXT,
thumbnail TEXT,
color TEXT,
message TEXT
);`, (err) => {
if (err) {
console.log('Error creating table', err);
}
});
});
// Set a cooldown for mentions in each channel
let cooldowns = new Map();
client.on('ready', () => {
console.log(`Bot is ready as: ${client.user.tag}!`);
});
client.on('message', async message => {
if (!message.content.startsWith(prefix) || message.author.bot) return;
const args = message.content.slice(prefix.length).trim().split(/ +/);
const command = args.shift().toLowerCase();
if (command === 'keyword') {
const subCommand = args.shift();
if (subCommand === 'add') {
// Check if the user has 'ADMINISTRATOR' permission
if (!message.member.hasPermission('ADMINISTRATOR')) {
return message.reply('You do not have permission to use this command.');
}
const keyword = args.shift();
const channelOrCategory = args.shift();
const role = message.mentions.roles.first();
if (!keyword || !channelOrCategory || !role) {
message.reply('Please provide a keyword, a channel or category, and mention a role.');
return;
}
db.run(`INSERT INTO keywords(keyword, channelOrCategory, role) VALUES(?, ?, ?)`, [keyword, channelOrCategory, role.name], function(err) {
if (err) {
return console.log(err.message);
}
message.reply(`Keyword "${keyword}" is now set for the channel/category "${channelOrCategory}" with role "${role.name}".`);
});
} else if (subCommand === 'delete') {
const keyword = args.shift();
if (!keyword) {
message.reply('Please provide a keyword to delete.');
return;
}
db.run(`DELETE FROM keywords WHERE keyword = ?`, keyword, function(err) {
if (err) {
return console.log(err.message);
}
if (this.changes > 0) {
message.reply(`Keyword "${keyword}" has been deleted.`);
} else {
message.reply(`Keyword "${keyword}" not found.`);
}
});
} else if (subCommand === 'list') {
db.all(`SELECT * FROM keywords`, [], (err, rows) => {
if (err) {
throw err;
}
let reply = 'Here are the keywords currently being monitored:n';
rows.forEach((row) => {
reply += `Keyword: ${row.keyword}, Channel/Category: ${row.channelOrCategory}, Role: ${row.role}n`;
});
message.reply(reply);
});
}
} else if (command === 'embed') {
// Check if the user has 'ADMINISTRATOR' permission
if (!message.member.hasPermission('ADMINISTRATOR')) {
return message.reply('You do not have permission to use this command.');
}
const keyword = args.shift();
const author = args.shift();
const thumbnail = args.shift();
const color = args.shift();
const messageContent = args.join(" ");
if (!keyword || !author || !thumbnail || !color || !messageContent) {
message.reply('Please provide a keyword, author, thumbnail url, color, and message.');
return;
}
db.run(`UPDATE keywords SET author = ?, thumbnail = ?, color = ?, message = ? WHERE keyword = ?`, [author, thumbnail, color, messageContent, keyword], function(err) {
if (err) {
return console.log(err.message);
}
if (this.changes > 0) {
message.reply(`Embed updated for keyword "${keyword}".`);
} else {
message.reply(`Keyword "${keyword}" not found.`);
}
});
} else if (command === 'help') {
message.channel.send(`
Here are the commands you can use:
+keyword add <keyword> <channel/category> @role - Adds a keyword to the database which triggers a role ping when found in a specific channel or category in an embed's title, description, or footer.
+keyword delete <keyword> - Deletes a keyword from the database.
+keyword list - Lists all keywords currently being monitored and their associated channels or categories.
+embed <keyword> <author> <thumbnail> <color> <message> - Sets a custom embed message for a keyword. The <color> should be a hex color code.
+help - Shows this help message.
`);
}
});
client.on('message', message => {
if (!message.embeds.length) return;
message.embeds.forEach(embed => {
db.all(`SELECT * FROM keywords`, [], (err, rows) => {
if (err) {
throw err;
}
rows.forEach((row) => {
if ((embed.title && embed.title.includes(row.keyword)) ||
(embed.description && embed.description.includes(row.keyword)) ||
(embed.footer && embed.footer.text.includes(row.keyword)) &&
(message.channel.name === row.channelOrCategory || message.channel.parent.name === row.channelOrCategory)) {
// If a mention has already been made in the last 15 seconds, don't mention again
if (cooldowns.get(message.channel.id)) return;
// Set a cooldown for the channel
cooldowns.set(message.channel.id, Date.now());
if (row.author && row.thumbnail && row.color && row.message) {
// Send a custom embed if one exists
const embedMessage = new Discord.MessageEmbed()
.setColor(row.color)
.setAuthor(row.author)
.setThumbnail(row.thumbnail)
.setDescription(row.message);
message.channel.send(embedMessage);
} else {
// Send a role mention if no custom embed exists
const role = message.guild.roles.cache.find(role => role.name === row.role);
if (role) {
message.channel.send(`${role} keyword found!`);
}
}
// Remove the cooldown after 15 seconds
setTimeout(() => {
cooldowns.delete(message.channel.id);
}, 15000);
}
});
});
});
});
client.login(process.env.DISCORD_BOT_TOKEN);
Was expecing it to respond to commands, it appears online but nothing happens.