├── README.md
├── config.js
├── commands
└── find.js
├── .gitignore
├── package.json
├── events
├── messageCreate.js
├── ready.js
└── interactionCreate.js
├── utils
└── serverList.js
└── index.js
/README.md:
--------------------------------------------------------------------------------
1 | # slash-command-bot-v14
2 | About Discord bot draft that does not contain ready-made commands, compatible with discord.js v14. Create your own discord bot with this slash command handler.
3 |
4 |
5 | Support: https://discord.gg/codes
6 |
--------------------------------------------------------------------------------
/config.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | //////////////////////////
3 | clientId: "",
4 | clientSecret: "",
5 | publicKey: "",
6 | token: "", //WRITE YOUR BOT TOKEN
7 | botStatus: "Umut Bayraktar ♥", //WRITE YOUR BOT STATUS.
8 | //////////////////////////
9 | }
10 |
--------------------------------------------------------------------------------
/commands/find.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | name: "find",
3 | description: "Find clients.",
4 | options: [],
5 | run: async (client, interaction) => {
6 | await execute(interaction);
7 | }
8 | };
9 |
10 | async function execute(interaction) {
11 | interaction.reply("pong")
12 | }
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Logs
2 | logs
3 | *.log
4 | npm-debug.log*
5 | yarn-debug.log*
6 | yarn-error.log*
7 | pnpm-debug.log*
8 | lerna-debug.log*
9 |
10 | node_modules
11 | dist
12 | dist-ssr
13 | *.local
14 |
15 | # Editor directories and files
16 | .vscode/*
17 | !.vscode/extensions.json
18 | .idea
19 | .DS_Store
20 | *.suo
21 | *.ntvs*
22 | *.njsproj
23 | *.sln
24 | *.sw?
25 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "discordjs-slash-command-bot-v14",
3 | "version": "1.0.0",
4 | "description": "discordjs-slash-command-bot-v14",
5 | "main": "index.js",
6 | "scripts": {
7 | "start": "nodemon index.js"
8 | },
9 | "keywords": [],
10 | "author": "Umut Bayraktar",
11 | "license": "MIT",
12 | "dependencies": {
13 | "discord.js": "^14.7.1",
14 | "fs": "^0.0.1-security",
15 | "nodemon": "^3.1.0"
16 | },
17 | "engines": {
18 | "node": "17.x"
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/events/messageCreate.js:
--------------------------------------------------------------------------------
1 | const { InteractionType } = require("discord.js");
2 | const fs = require("fs");
3 |
4 | module.exports = async (client, message) => {
5 | if (message.content === 'ping') {
6 | message.reply('pong');
7 | message.channel.send('pong');
8 | } else if (message.content.startsWith('!kick')) {
9 | if (message.mentions.users.size) {
10 | const taggedUser = message.mentions.users.first();
11 | message.channel.send(`You wanted to kick: ${taggedUser.username}`);
12 | } else {
13 | message.reply('Please tag a valid user!');
14 | }
15 | }
16 | };
17 |
--------------------------------------------------------------------------------
/events/ready.js:
--------------------------------------------------------------------------------
1 | const config = require("../config.js");
2 | const { REST } = require("@discordjs/rest");
3 | const { Routes } = require("discord-api-types/v10");
4 |
5 | module.exports = async (client) => {
6 | console.log(`${client.user.tag} Bot Online!`)
7 |
8 | client.user.setActivity(config.botStatus)
9 |
10 | const rest = new REST({ version: "10" }).setToken(config.token);
11 | (async () => {
12 | try {
13 | await rest.put(Routes.applicationCommands(client.user.id), {
14 | body: await client.commands,
15 | });
16 | console.log("Successfully loadded application [/] commands.");
17 | } catch (e) {
18 | console.log("Failed to load application [/] commands. " + e);
19 | }
20 | })();
21 | }
22 |
--------------------------------------------------------------------------------
/events/interactionCreate.js:
--------------------------------------------------------------------------------
1 | const { InteractionType } = require("discord.js");
2 | const fs = require("fs");
3 | module.exports = async (client, interaction) => {
4 | if (!interaction.guild) return;
5 | if (interaction.user.bot) return;
6 |
7 | if (interaction.type === InteractionType.ApplicationCommand) {
8 | fs.readdir("./commands", (err, files) => {
9 | if (err) throw err;
10 | files.forEach(async (f) => {
11 | let props = require(`../commands/${files}`);
12 | if (interaction.commandName.toLowerCase() === props.name.toLowerCase()) {
13 | try {
14 | return props.run(client, interaction);
15 | } catch (e) {
16 | return interaction.reply({ content: `ERROR\n\n\`\`\`${e.message}\`\`\``, ephemeral: true }).catch(e => { })
17 | }
18 | }
19 | });
20 | });
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/utils/serverList.js:
--------------------------------------------------------------------------------
1 | // get server list to joined bot
2 | async function getServerList(interaction) {
3 | try {
4 | // Fetch all guilds that the bot is a member of
5 | const partialGuilds = await interaction.client.guilds.fetch();
6 | const guilds = await Promise.all(
7 | partialGuilds.map((partialGuild) => partialGuild.fetch()),
8 | );
9 |
10 | // Filter guilds to find those where the user is a member
11 | const userGuilds = guilds.filter((guild) =>
12 | guild.members.cache.has(interaction.user.id),
13 | );
14 | const guildIDs = userGuilds.map((guild) => guild.id);
15 |
16 | // Reply to the interaction with a list of guild IDs
17 | await interaction.reply(`You are a member of the following guilds:\n${guildIDs.join('\n')}`);
18 | } catch (error) {
19 | console.error('Error executing command:', error);
20 | await interaction.reply({ content: 'An error occurred while processing your command.', ephemeral: true });
21 | }
22 | }
--------------------------------------------------------------------------------
/index.js:
--------------------------------------------------------------------------------
1 | const { Client, GatewayIntentBits, Partials } = require("discord.js");
2 | const config = require("./config.js");
3 | const fs = require("fs");
4 | const client = new Client({
5 | partials: [
6 | Partials.Message, // for message
7 | Partials.Channel, // for text channel
8 | Partials.GuildMember, // for guild member
9 | Partials.Reaction, // for message reaction
10 | Partials.GuildScheduledEvent, // for guild events
11 | Partials.User, // for discord user
12 | Partials.ThreadMember, // for thread member
13 | ],
14 | intents: [
15 | GatewayIntentBits.Guilds, // for guild related things
16 | GatewayIntentBits.GuildMembers, // for guild members related things
17 | GatewayIntentBits.GuildBans, // for manage guild bans
18 | GatewayIntentBits.GuildEmojisAndStickers, // for manage emojis and stickers
19 | GatewayIntentBits.GuildIntegrations, // for discord Integrations
20 | GatewayIntentBits.GuildWebhooks, // for discord webhooks
21 | GatewayIntentBits.GuildInvites, // for guild invite managing
22 | GatewayIntentBits.GuildVoiceStates, // for voice related things
23 | GatewayIntentBits.GuildPresences, // for user presence things
24 | GatewayIntentBits.GuildMessages, // for guild messages things
25 | GatewayIntentBits.GuildMessageReactions, // for message reactions things
26 | GatewayIntentBits.GuildMessageTyping, // for message typing things
27 | GatewayIntentBits.DirectMessages, // for dm messages
28 | GatewayIntentBits.DirectMessageReactions, // for dm message reaction
29 | GatewayIntentBits.DirectMessageTyping, // for dm message typinh
30 | GatewayIntentBits.MessageContent, // enable if you need message content things
31 | ],
32 | });
33 |
34 | module.exports = client;
35 |
36 | fs.readdir("./events", (err, files) => {
37 | if (err) throw err;
38 | files.forEach((file) => {
39 | if (!file.endsWith(".js")) return;
40 | const event = require(`./events/${file}`);
41 | let eventName = file.split(".")[0];
42 | console.log(`👌 Loadded Event: ${eventName}`);
43 | client.on(eventName, event.bind(null, client));
44 | delete require.cache[require.resolve(`./events/${file}`)];
45 | });
46 | });
47 |
48 | client.commands = [];
49 | fs.readdir("./commands", (err, files) => {
50 | if (err) throw err;
51 | files.forEach(async (file) => {
52 | if (!file.endsWith(".js")) return;
53 | try {
54 | let props = require(`./commands/${file}`);
55 | client.commands.push({
56 | name: props.name,
57 | description: props.description,
58 | options: props.options
59 | });
60 | console.log(`Loaded command: ${props.name}`);
61 | } catch (err) {
62 | console.log(err);
63 | }
64 | });
65 | });
66 |
67 | client.login(config.token || process.env.TOKEN).catch(e => {
68 | console.log("The Bot Token You Entered Into Your Project Is Incorrect Or Your Bot's INTENTS Are OFF!")
69 | })
70 |
--------------------------------------------------------------------------------