From 584afd0fe64d6a90d9ba6e7a4aaecc16a1536ea9 Mon Sep 17 00:00:00 2001 From: Noah Pombas Date: Sun, 21 Apr 2024 19:07:51 +0200 Subject: [PATCH] Update 1.0.0 --- .env | 1 + README.md | 10 ++-- commands/moderation/moveuser.js | 87 ++++++++++++++++++++++++++++++ events/client/interactionCreate.js | 39 ++++++++++++++ events/client/messageCreate.js | 35 ++++++++++++ events/client/ready.js | 32 +++++++++++ handler/index.js | 64 ++++++++++++++++++++++ index.js | 14 +++++ package.json | 17 ++++++ 9 files changed, 296 insertions(+), 3 deletions(-) create mode 100644 .env create mode 100644 commands/moderation/moveuser.js create mode 100644 events/client/interactionCreate.js create mode 100644 events/client/messageCreate.js create mode 100644 events/client/ready.js create mode 100644 handler/index.js create mode 100644 index.js create mode 100644 package.json diff --git a/.env b/.env new file mode 100644 index 0000000..66eca1b --- /dev/null +++ b/.env @@ -0,0 +1 @@ +token=yourDiscordBotToken \ No newline at end of file diff --git a/README.md b/README.md index e2a0b34..a8f848d 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,11 @@ a Discord BOT with User friendly commands, moderation commands and more! ## Instructions -- create a .env File - - token=yourDiscordBotToken -- npm i (to download all libraries) +- .env + - replace yourDiscordBotToken with your Token +- handler/index.js + - replace yourDiscordServerID with your discord server ID + - Important: The Bot needs to be in the server! + +- npm i (download all libraries) - node index.js (to start the bot) diff --git a/commands/moderation/moveuser.js b/commands/moderation/moveuser.js new file mode 100644 index 0000000..3586fe0 --- /dev/null +++ b/commands/moderation/moveuser.js @@ -0,0 +1,87 @@ +const Discord = require("discord.js"); + +module.exports = { + name: "move-user", + description: "[ 🧹 Mover Members ] Move a member from a voice channel to another.", + type: Discord.ApplicationCommandType.ChatInput, + options: [ + { + name: "channel", + description: "The new Channel you want to move the User.", + channelTypes: [ + Discord.ChannelType.GuildVoice + ], + type: Discord.ApplicationCommandOptionType.Channel, + required: true, + }, + { + name: "member", + description: "Choose a member", + type: Discord.ApplicationCommandOptionType.User, + required: true, + }, + ], + + run: async (client, interaction) => { + if (!interaction.member.permissions.has(Discord.PermissionFlagsBits.MoveMembers)) + return interaction.reply({ content: `**Error: Permission Denied!**`, ephemeral: true }) + + + let channel = interaction.options.getChannel("channel") + let user = interaction.options.getUser("member") + let member = interaction.guild.members.cache.get(user.id) + + if (!member) + return interaction.reply({ content: `**Error: Member not found**`, ephemeral: true }) + + + if (!member.voice.channel) + return interaction.reply({ content: `**Error: This member is not in a voice channel**`, ephemeral: true }) + + + try { + + await interaction.deferReply({}) + + let embedVoice = new Discord.EmbedBuilder() + .setAuthor({ name: `Admin: ${interaction.user.username}`, iconURL: interaction.user.displayAvatarURL() }) + .setColor("Green") + .setFooter({ text: `Member moved: ${member.user.username}`, iconURL: member.user.displayAvatarURL() }) + .setTimestamp() + .setURL(`https://discord.com/channels/${interaction.guild.id}/${canalV.id}`) + .setTitle("🧹 - Member Moved!") + .setThumbnail(interaction.guild.iconURL({ dynamic: true, extension: 'png' })) + .setDescription("*✅ - Member moved successfully!*") + .setFields( + { + name: "🎙 - Voice Channel:", + value: `*${canalV}*`, + inline: true + }, + { + name: "🆔 - Voice Chanel ID:", + value: `*${canalV.id}*`, + inline: true + }, + { + name: "👤 - Moved Member:", + value: `*${member}*`, + inline: true + }, + { + name: "🆔 - Moved member ID:", + value: `*${member.id}*`, + inline: true + } + ) + + await interaction.editReply({ embeds: [embedVoice] }) + member.voice.setChannel(channel) + + } catch { + interaction.editReply({ content: `**Error: Something didn't work...**`, ephemeral: true }) + } + + + } +} \ No newline at end of file diff --git a/events/client/interactionCreate.js b/events/client/interactionCreate.js new file mode 100644 index 0000000..4d7f64c --- /dev/null +++ b/events/client/interactionCreate.js @@ -0,0 +1,39 @@ +const {InteractionType} = require("discord.js") +module.exports = { + name: 'interactionCreate', + + /** + * @param {CommandInteraction} interaction + * @param {Client} client + */ + async execute(interaction, client) { + + if (interaction.type !== InteractionType.ApplicationCommand) return; + + const command = client.slash.get(interaction.commandName); + if (!command) return interaction.reply({ content: `Command doesn't exist!`, ephemeral: true }); + + if (command.ownerOnly) { + if (interaction.user.id !== client.config.ownerID) { + return interaction.reply({ content: `Permission Denied`, ephemeral: true }); + } + } + + const args = []; + + for (let option of interaction.options.data) { + if (option.type === 'SUB_COMMAND') { + if (option.name) args.push(option.name); + option.options?.forEach(x => { + if (x.value) args.push(x.value); + }); + } else if (option.value) args.push(option.value); + } + + try { + command.run(client, interaction, args) + } catch (e) { + interaction.reply({ content: e.message }); + } + } +} \ No newline at end of file diff --git a/events/client/messageCreate.js b/events/client/messageCreate.js new file mode 100644 index 0000000..d6cce8a --- /dev/null +++ b/events/client/messageCreate.js @@ -0,0 +1,35 @@ +module.exports = { + name: 'messageCreate', + + /** + * @param {Message} message + * @param {Client} client + */ + async execute(message, client) { + if (message.author.bot || !message.guild || !message.content.toLowerCase().startsWith(client.config.botPrefix)) return; + const [cmd, ...args] = message.content.slice(client.config.botPrefix.length).trim().split(" "); + const command = client.commands.get(cmd.toLowerCase()) || client.commands.find(c => c.aliases?.includes(cmd.toLowerCase())); + + //Se quiser que o bot não retorne nada caso o comando não existe + //if (!command) { return } + + //Se quiser que o bot retorne alguma mensagem + if (!command) { + return message.reply({ content: `:x: **|** Comando não encontrado` }) + } + + //Se quiser que o bot não retorne nada ao usar um comando apenas para dev + /*if (command.ownerOnly) { + if (message.author.id !== client.config.ownerID) { return } + }*/ + + //se quiser que o bot retorne alguma mensagem + if (command.ownerOnly) { + if (message.author.id !== client.config.ownerID) { + return message.reply({ content: `:x: **|** Apenas meu criador pode usar esse comando!` }) + } + } + + await command.run(client, message, args); + } +} \ No newline at end of file diff --git a/events/client/ready.js b/events/client/ready.js new file mode 100644 index 0000000..0de280b --- /dev/null +++ b/events/client/ready.js @@ -0,0 +1,32 @@ +const client = require("../../index"); +const { ActivityType } = require('discord.js') +const chalk = require("chalk"); +const { joinVoiceChannel } = require("@discordjs/voice"); +const Discord = require('discord.js') + +module.exports = { + name: 'ready', + once: true, + + /** + * @param {Client} client + */ + async execute(client) { + + let status = [ + `by info@noahpombas.ch`, + `Spoiler: novo Servidor de Minecraft brevemente` + ], + i = 0 + setInterval(() => { + client.user.setActivity(`${status[i++ % status.length]}`, { + type: ActivityType.Streaming + }) + }, 5000); + + + + + console.log(chalk.blueBright(`[READY] Bot Online!`)); + } +} diff --git a/handler/index.js b/handler/index.js new file mode 100644 index 0000000..cba5afe --- /dev/null +++ b/handler/index.js @@ -0,0 +1,64 @@ +const fs = require("node:fs"); +const chalk = require("chalk"); + +//Carregar eventos +const loadEvents = async function (client) { + const eventFolders = fs.readdirSync("./events"); + for (const folder of eventFolders) { + const eventFiles = fs + .readdirSync(`./events/${folder}`) + .filter((file) => file.endsWith(".js")); + + for (const file of eventFiles) { + const event = require(`../events/${folder}/${file}`); + + if (event.name) { + console.log(chalk.greenBright(` ✔️ => ${file} Event loaded.`)); + } else { + console.log(chalk.redBright(` ❌ => ${file} Event not loaded.`)); + continue; + } + + if (event.once) { + client.once(event.name, (...args) => event.execute(...args, client)); + } else { + client.on(event.name, (...args) => event.execute(...args, client)); + } + } + } +} + + +//Carregar slashcommands +const loadSlashCommands = async function (client) { + let slash = [] + + const commandFolders = fs.readdirSync("./commands"); + for (const folder of commandFolders) { + const commandFiles = fs + .readdirSync(`./commands/${folder}`) + .filter((file) => file.endsWith(".js")); + + for (const file of commandFiles) { + const command = require(`../commands/${folder}/${file}`); + + if (command.name) { + client.slash.set(command.name, command); + slash.push(command) + console.log(chalk.greenBright(` ✔️ => ${file} Command loaded`)); + } else { + console.log(chalk.redBright(` ❌ => ${file} Command not loaded`)); + continue; + } + } + } + + client.on("ready", async () => { + await client.guilds.cache.get("yourDiscordServerID").commands.set(slash); + }) +} + +module.exports = { + loadEvents, + loadSlashCommands +} \ No newline at end of file diff --git a/index.js b/index.js new file mode 100644 index 0000000..27db393 --- /dev/null +++ b/index.js @@ -0,0 +1,14 @@ +const Discord = require("discord.js"); +const client = new Discord.Client({intents: 32767}); +const handler = require("./handler/index"); +require("dotenv").config() + +module.exports = client; +client.discord = Discord; + +client.slash = new Discord.Collection(); + +handler.loadEvents(client); +handler.loadSlashCommands(client); + +client.login(process.env.TOKEN); \ No newline at end of file diff --git a/package.json b/package.json new file mode 100644 index 0000000..ef7a059 --- /dev/null +++ b/package.json @@ -0,0 +1,17 @@ +{ + "name": "project-bot", + "version": "1.0.0", + "description": "", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "author": "noahpombas.ch", + "license": "ISC", + "dependencies": { + "@discordjs/voice": "^0.16.1", + "chalk": "^4.1.2", + "discord.js": "^14.12.1", + "dotenv": "^16.4.5" + } +}