Update 1.0.0

This commit is contained in:
Noah Pombas
2024-04-21 19:07:51 +02:00
parent a58330ec0a
commit 584afd0fe6
9 changed files with 296 additions and 3 deletions

1
.env Normal file
View File

@@ -0,0 +1 @@
token=yourDiscordBotToken

View File

@@ -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)

View File

@@ -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 })
}
}
}

View File

@@ -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 });
}
}
}

View File

@@ -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);
}
}

32
events/client/ready.js Normal file
View File

@@ -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!`));
}
}

64
handler/index.js Normal file
View File

@@ -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
}

14
index.js Normal file
View File

@@ -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);

17
package.json Normal file
View File

@@ -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"
}
}