Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
blodef authored Jun 19, 2023
1 parent ba2ee4b commit 43e9b31
Show file tree
Hide file tree
Showing 7 changed files with 159 additions and 0 deletions.
12 changes: 12 additions & 0 deletions slash-command-bot-main/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# slash-command-bot-v14
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.

<hr>
Follow Me Social Media<br>
Twitch Yayınları: https://twitch.com/umutxyp<br>
Github: https://github.com/umutxyp<br>
Instagram: https://instagram.com/umutxyp<br>
Twitter: https://twitter.com/devbayraktar<br>
Facebook: https://facebook.com/umutxyp<br>
Pinterest: https://pinterest.com/umutxyp<br>
TikTok: https://www.tiktok.com/@umutxyp
10 changes: 10 additions & 0 deletions slash-command-bot-main/commands/ping.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module.exports = {
name: "ping",
description: "View bot ping.",
options: [],
run: async (client, interaction) => {

interaction.reply("pong")

},
};
6 changes: 6 additions & 0 deletions slash-command-bot-main/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {
//////////////////////////
token: "", //WRITE YOUR BOT TOKEN
botStatus: "Umut Bayraktar ♥", //WRITE YOUR BOT STATUS.
//////////////////////////
}
23 changes: 23 additions & 0 deletions slash-command-bot-main/events/interactionCreate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
const { InteractionType } = require("discord.js");
const fs = require("fs");
module.exports = async(client, interaction) => {
if(!interaction.guild) return;
if(interaction.user.bot) return;

if (interaction.type === InteractionType.ApplicationCommand) {
fs.readdir("./commands", (err, files) => {
if (err) throw err;
files.forEach(async (f) => {
let props = require(`../commands/${f}`);
if (interaction.commandName.toLowerCase() === props.name.toLowerCase()) {
try {
return props.run(client, interaction);
} catch (e) {
return interaction.reply({ content: `ERROR\n\n\`\`\`${e.message}\`\`\``, ephemeral: true }).catch(e => { })
}
}
});
});
}

}
22 changes: 22 additions & 0 deletions slash-command-bot-main/events/ready.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const config = require("../config.js");
const { REST } = require("@discordjs/rest");
const { Routes } = require("discord-api-types/v10");

module.exports = async (client) => {
console.log(`${client.user.tag} Bot Online!`)

client.user.setActivity(config.botStatus)

const rest = new REST({ version: "10" }).setToken(config.token);
(async () => {
try {
await rest.put(Routes.applicationCommands(client.user.id), {
body: await client.commands,
});
console.log("Successfully loadded application [/] commands.");
} catch(e) {
console.log("Failed to load application [/] commands. " + e);
}
})();

}
67 changes: 67 additions & 0 deletions slash-command-bot-main/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
const { Client, GatewayIntentBits, Partials } = require("discord.js");
const config = require("./config.js");
const fs = require("fs");
const client = new Client({
partials: [
Partials.Message, // for message
Partials.Channel, // for text channel
Partials.GuildMember, // for guild member
Partials.Reaction, // for message reaction
Partials.GuildScheduledEvent, // for guild events
Partials.User, // for discord user
Partials.ThreadMember, // for thread member
],
intents: [
GatewayIntentBits.Guilds, // for guild related things
GatewayIntentBits.GuildMembers, // for guild members related things
GatewayIntentBits.GuildBans, // for manage guild bans
GatewayIntentBits.GuildEmojisAndStickers, // for manage emojis and stickers
GatewayIntentBits.GuildIntegrations, // for discord Integrations
GatewayIntentBits.GuildWebhooks, // for discord webhooks
GatewayIntentBits.GuildInvites, // for guild invite managing
GatewayIntentBits.GuildVoiceStates, // for voice related things
GatewayIntentBits.GuildPresences, // for user presence things
GatewayIntentBits.GuildMessages, // for guild messages things
GatewayIntentBits.GuildMessageReactions, // for message reactions things
GatewayIntentBits.GuildMessageTyping, // for message typing things
GatewayIntentBits.DirectMessages, // for dm messages
GatewayIntentBits.DirectMessageReactions, // for dm message reaction
GatewayIntentBits.DirectMessageTyping, // for dm message typinh
GatewayIntentBits.MessageContent, // enable if you need message content things
],
});

module.exports = client;

fs.readdir("./events", (_err, files) => {
files.forEach((file) => {
if (!file.endsWith(".js")) return;
const event = require(`./events/${file}`);
let eventName = file.split(".")[0];
console.log(`👌 Loadded Event: ${eventName}`);
client.on(eventName, event.bind(null, client));
delete require.cache[require.resolve(`./events/${file}`)];
});
});

client.commands = [];
fs.readdir("./commands", (err, files) => {
if (err) throw err;
files.forEach(async (f) => {
try {
let props = require(`./commands/${f}`);
client.commands.push({
name: props.name,
description: props.description,
options: props.options
});
console.log(`Loaded command: ${props.name}`);
} catch (err) {
console.log(err);
}
});
});

client.login(config.token || process.env.TOKEN).catch(e => {
console.log("The Bot Token You Entered Into Your Project Is Incorrect Or Your Bot's INTENTS Are OFF!")
})
19 changes: 19 additions & 0 deletions slash-command-bot-main/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "discordjs-slash-command-bot-v14",
"version": "1.0.0",
"description": "discordjs-slash-command-bot-v14",
"main": "index.js",
"scripts": {
"start": "node index.js"
},
"keywords": [],
"author": "Umut Bayraktar",
"license": "MIT",
"dependencies": {
"discord.js": "^14.7.1",
"fs": "^0.0.1-security"
},
"engines": {
"node": "17.x"
}
}

0 comments on commit 43e9b31

Please sign in to comment.