Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
n-gonzz authored Oct 24, 2024
1 parent 38d9fdf commit c8f2993
Show file tree
Hide file tree
Showing 15 changed files with 489 additions and 2 deletions.
30 changes: 28 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,28 @@
# bot-discord
Base para BOT de Discord en Node.js
<div align="center">
<a href="https://discord.js.org"><img src="https://discord.js.org/static/logo.svg" width="546" alt="discord.js" /></a>
</div>

# Base para BOT de Discord con comandos básicos
- Comandos: avatar, ayuda, ban, clear, invitar, md, ping o server.
- Otros: Configuracuón de Actividad, paquete discord.js, mensajes en español.

# Sobre
Este bot ha sido desarrollado con NODE.js y Visual Studio Code.
- Requisitos
Se necesita Node.js 16.11.0 o superior.

# Pasos a seguir
- Añade el bot a tu servidor mediante el [Portal de Desarrolladores de Discord](https://discord.com/developers/applications/).
- Añade el TOKEN de tu bot al archivo principal.
- Ejecuta el archivo "iniciar.bat" y espera un poco.


# Referencias

- [NPM.js](https://www.npmjs.com/package/discord.js)
- [Discord.js](https://discord.js.org/)
- [Repositorio de Discord.js](https://github.com/discordjs/discord.js)

---------------------------------------------------------------------------

Desarrollado con Node.js 16.11.0
40 changes: 40 additions & 0 deletions bot.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
const fs = require('fs');
const Discord = require('discord.js');
const client = new Discord.Client({
intents: 33283
})

client.commands = new Discord.Collection();
const commandFiles = fs.readdirSync('./comandos').filter(file => file.endsWith('.js'));

for (const file of commandFiles) {
const command = require(`./comandos/${file}`);
client.commands.set(command.name, command);
}

client.once('ready', () => {
console.log('¡Estamos en línea!');
client.user.setPresence({ activities: [{ name: 'En desarrollo...', type: 'PLAYING' // 'PLAYING', 'WATCHING', 'LISTENING', 'STREAMING'
}] });
});


client.on('messageCreate', message => {
if (!message.content.startsWith('.') || message.author.bot) return;

const args = message.content.slice(1).trim().split(/ +/);
const commandName = args.shift().toLowerCase();

if (!client.commands.has(commandName)) return;

const command = client.commands.get(commandName);

try {
command.execute(message, args);
} catch (error) {
console.error(error);
message.reply('¡Hubo un error al ejecutar ese comando!');
}
});

client.login('TOKEN_AQUI');
8 changes: 8 additions & 0 deletions comandos/avatar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module.exports = {
name: 'avatar',
description: 'Muestra el avatar de un usuario',
execute(message, args) {
const user = message.mentions.users.first() || message.author;
message.channel.send(`Avatar de ${user.username}: ${user.displayAvatarURL({ format: 'png', dynamic: true, size: 1024 })}`);
},
};
16 changes: 16 additions & 0 deletions comandos/ayuda.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module.exports = {
name: 'ayuda',
execute(message, args) {
message.channel.send('¡Aquí tienes una lista de comandos disponibles!');
message.channel.send('- .hola: Responde con "¡Hola!"');
message.channel.send('- .ayuda: Muestra esta lista de comandos');
message.channel.send('- .ping: Responde con la latencia del bot');
message.channel.send('- .invitar: Proporciona un enlace para invitar al bot a tu servidor');

message.channel.send('- .avatar: Proporciona la imagen de perfil de un usuario');
message.channel.send('- .server: Muestra información sobre el servidor');
message.channel.send('- .ban: Permite bloquear a un miembro del servidor');
message.channel.send('- .clear: Permite borrar una cantidad de mensajes en el chat');
message.channel.send('- .md: Permite enviar un mensaje privado a un usuario del servidor');
},
};
32 changes: 32 additions & 0 deletions comandos/ban.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
module.exports = {
name: 'ban',
description: 'Banea a un usuario mencionado',
usage: '.ban <usuario> [motivo]',
execute(message, args) {
// Verificar que el autor del mensaje tiene permisos para banear.
if (!message.member.permissions.has('BAN_MEMBERS')) {
return message.channel.send('No tienes permisos para banear miembros.');
}

// Mencionar al usuario que se va a banear.
const userToBan = message.mentions.members.first();

// Verificar si se mencionó un usuario válido.
if (!userToBan) {
return message.channel.send('Por favor, menciona al usuario que deseas banear.');
}

// Obtener el motivo del ban, si se proporciona.
const reason = args.slice(1).join(' ');

// Banear al usuario.
userToBan.ban({ reason: reason })
.then(() => {
message.channel.send(`Se ha baneado a ${userToBan.user.tag}.`);
})
.catch(error => {
console.error('Error al banear al usuario:', error);
message.channel.send('Ha ocurrido un error al intentar banear al usuario.');
});
},
};
21 changes: 21 additions & 0 deletions comandos/clear.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
module.exports = {
name: 'clear',
description: 'Borra una cantidad específica de mensajes en el canal actual',
usage: '.clear <cantidad>',
execute(message, args) {
const amount = parseInt(args[0]);

if (isNaN(amount)) {
return message.reply('Por favor, proporciona un número válido para la cantidad de mensajes a borrar.');
} else if (amount <= 0 || amount > 100) {
return message.reply('La cantidad de mensajes a borrar debe estar entre 1 y 100.');
}

message.channel.bulkDelete(amount + 1)
.then(messages => message.channel.send(`Se han borrado ${messages.size - 1} mensajes.`))
.catch(error => {
console.error('Error al borrar mensajes:', error);
message.channel.send('Hubo un error al intentar borrar mensajes.');
});
},
};
6 changes: 6 additions & 0 deletions comandos/hola.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {
name: 'hola',
execute(message, args) {
message.channel.send('¡Hola!');
},
};
6 changes: 6 additions & 0 deletions comandos/invitar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {
name: 'invitar',
execute(message, args) {
message.channel.send('¡Aquí tienes el enlace para invitarme a tu servidor! https://discord.com/oauth2/authorize?client_id=1164632567065104515&scope=bot&permissions=8');
},
};
25 changes: 25 additions & 0 deletions comandos/md.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
module.exports = {
name: 'md',
description: 'Envía un mensaje privado a un usuario mencionado',
usage: '.md <usuario> <mensaje>',
execute(message, args) {
// Verificar si se mencionó un usuario válido.
const userToDM = message.mentions.users.first();
if (!userToDM) {
return message.channel.send('Por favor, menciona al usuario al que deseas enviar un mensaje privado.');
}

// Obtener el mensaje a enviar.
const messageContent = args.slice(1).join(' ');

// Enviar el mensaje privado.
userToDM.send(`Mensaje privado de ${message.author.username}: ${messageContent}`)
.then(() => {
message.channel.send(`Se ha enviado un mensaje privado a ${userToDM.tag}.`);
})
.catch(error => {
console.error('Error al enviar mensaje privado:', error);
message.channel.send('Ha ocurrido un error al intentar enviar el mensaje privado.');
});
},
};
7 changes: 7 additions & 0 deletions comandos/ping.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = {
name: 'ping',
execute(message, args) {
let ping = Math.floor(message.client.ws.ping);
message.channel.send(":ping_pong: Pong!, "+ ping + "ms");
},
};
17 changes: 17 additions & 0 deletions comandos/server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const { EmbedBuilder } = require('discord.js');

module.exports = {
name: 'server',
execute(message, args) {
const embed = new EmbedBuilder ()
.setColor('#0099ff')
.setTitle('Datos del Servidor')
.setDescription(`Nombre del servidor: ${message.guild.name}
\nTotal miembros: ${message.guild.memberCount}
\nID del Servidor: ${message.guild.id}
\nRegión del Servidor: ${message.guild.region}`)
.setTimestamp()

message.channel.send({ embeds: [embed] });
},
};
3 changes: 3 additions & 0 deletions iniciar.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@echo off
node bot.js
pause
Binary file added node_modules.zip
Binary file not shown.
Loading

0 comments on commit c8f2993

Please sign in to comment.