A discord bot that I made, contains slash commands & may contain more in the future
</> MutilpleBot, On Discord.js V14 as of 5/16/2023 </>
<!>Copyright Notice<!>:
When taking the code for the bot you agree to the copyright license.
Discord bot:
information about discord intents: https://gist.github.com/advaith1/e69bcc1cdd6d0087322734451f15aa2f
_Tiny Note: Please atleast do some modifications and make sure its not too simular (by too simular, don't just add a comment to one line of the code or such, ex:
//this does this
Slash commands:
You may view the slash commands of the bot by going into slashcommands folder
Notes:
This bot runs on node.js. You will need at least node 16.18.1
Make sure your bot has Message Content Intent enabled else you'll get a error.
This bot runs on replit (hosted there) and it is recommended to run it there.
NOTE: IF THERES A ERROR IN YOUR CODE OR SUCH, PLEASE REVIEW YOURSELF AND IF YOU SEE ANY throw new error PAY ATTENTION TO THAT AND SEE THE REASON
Secrets are environment variables (on replit you can create secrets by using it's bulit-in gui)
You'll need your bot token.
or download the latest github (github release is recommanded as it is likely more stable however if you want to be uptodate with the bot code, then import).
Make sure to run
npm install
Create a secret named TOKEN and value as the token of your bot.
Don't use the example I provided, put your own, it won't work. If you don't have a MongoDB, you can create one at MongoDB.
i did step 15 but did not save my API key!
if you have read all of this and understood (for example you not gonna claim you made this bot), Thank you, Have a great day!
if you have two slash commands named the exact same, run this (via runcode) to remove the duplicate?:
const { GatewayIntentBits, Partials, Client } = require('discord.js');
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent,
GatewayIntentBits.GuildMessageReactions,
],
partials: [Partials.Message, Partials.Reaction, Partials.Channel],
});
client.login(process.env.TOKEN);
client.on('ready', async () => {
try {
const guilds = client.guilds.cache;
const totalGuilds = guilds.size;
let deletedGuilds = 0;
for (const guild of guilds.values()) {
try {
const commands = await guild.commands.fetch();
const commandIDs = commands.map((command) => command.id);
console.log(`Command IDs in guild ${guild.id}: ${commandIDs.join(', ')}`);
await Promise.all(commandIDs.map((commandID) => guild.commands.delete(commandID)));
console.log(`Deleted ${commandIDs.length} commands in guild ${guild.id}`);
deletedGuilds++;
console.log(`Deleted commands in ${deletedGuilds} out of ${totalGuilds} guilds`);
} catch (error) {
console.error(`Failed to delete commands in guild ${guild.id}:`);
console.error(error);
}
}
console.log(`Total deleted commands: ${deletedGuilds}`);
} catch (error) {
console.error('Failed to fetch guilds:');
console.error(error);
}
});
To delete a specific global command?:
const { GatewayIntentBits, Partials, Client, REST, Routes, Events } = require('discord.js');
const client = new Client({ intents: [ GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages, GatewayIntentBits.MessageContent, GatewayIntentBits.GuildMessageReactions, ], partials: [Partials.Message, Partials.Reaction, Partials.Channel], });
client.login(process.env.TOKEN);
const rest = new REST({ version: '10' }).setToken(process.env.TOKEN);
client.on('ready', async () => { try { await rest.delete(Routes.applicationCommand('clientid', 'commandid')); console.log('Successfully deleted application command'); } catch (error) { console.error('Failed to delete application command'); console.error(error); } });