fix: try catch all moderation commands

This commit is contained in:
2022-09-02 13:34:24 +02:00
parent b2544f2e42
commit 91a82232bf
10 changed files with 73 additions and 51 deletions

View File

@@ -10,4 +10,4 @@ RUN npm install -g ts-node typescript
COPY . .
CMD ts-node index.ts
CMD ts-node --transpile-only index.ts

View File

@@ -22,7 +22,7 @@ export default commandModule({
} else if (value.indexOf('sugerencia') >= 0 || value.indexOf('sugerencias') >= 0) {
modal.reply({content: 'No puedes enviar una sugerencia con la palabra sugerencia(s).'})
} else {
// then we create the embed which will be sent when the thing is sent
// we create the embed which will be sent when the thing is sent
const modalEmbed = new EmbedBuilder()
.setColor("Random")
.setTitle('Sugerencia')
@@ -30,7 +30,7 @@ export default commandModule({
.setDescription(value);
// finally send the message to the text channel
const message1 = modal.client.guilds.cache.get('928018226330337280').channels.cache.get('1007269448140476436') as TextChannel
const message2 = await (await message1.send({embeds: [modalEmbed]}))
const message2 = (await message1.send({embeds: [modalEmbed]}))
message2.startThread({name: `Sugerencia de ${modal.user.username}`, autoArchiveDuration: ThreadAutoArchiveDuration.ThreeDays, reason: 'AUTOMATIZADO: Hilo para discutir sobre la sugerencia.'})
message2.react("✅")
message2.react("❎")

View File

@@ -22,11 +22,15 @@ export default commandModule({
}],
//alias : [],
execute: async (ctx, options, message) => {
const userToBan = options[1].getMember('usuario', true);
const reason = options[1].get('razon', true).value;
userToBan.ban(reason)
const sendToMods = ctx.client.guilds.cache.get('928018226330337280')!.channels.cache.get('1004118323258208257')
await sendToMods.send({content: `Se ha baneado a ${userToBan}.\nBan efectuado por ${ctx.user} con razón "${reason}."`})
await ctx.reply({content: 'Baneado correctamente!', ephemeral: true})
try {
const userToBan = options[1].getMember('usuario', true);
const reason = options[1].get('razon', true).value;
userToBan.ban(reason)
const sendToMods = ctx.client.guilds.cache.get('928018226330337280')!.channels.cache.get('1004118323258208257')
await sendToMods.send({content: `Se ha baneado a ${userToBan}.\nBan efectuado por ${ctx.user} con razón "${reason}."`})
await ctx.reply({content: 'Baneado correctamente!', ephemeral: true})
} catch (e) {
await ctx.reply({content: `ERROR: No puedo hacer este comando porque a lo mejor soy inferior que el rol de esa persona o estoy usándolo contra admins.`})
}
},
});

View File

@@ -28,12 +28,16 @@ export default commandModule({
}
],
execute: async (ctx, options) => {
const idMensaje = options[1].getString('id', true);
const channelID = options[1].getChannel('canal', true).id || ctx.channel.id
const guildId = ctx.guild.id
const guild = await ctx.client.guilds.fetch(guildId);
const channel = await guild.channels.fetch(channelID);
(await channel.messages.fetch(idMensaje)).delete();
await ctx.reply({content: 'Mensaje eliminado correctamente.', ephemeral: true});
try {
const idMensaje = options[1].getString('id', true);
const channelID = options[1].getChannel('canal', true).id || ctx.channel.id
const guildId = ctx.guild.id
const guild = await ctx.client.guilds.fetch(guildId);
const channel = await guild.channels.fetch(channelID);
(await channel.messages.fetch(idMensaje)).delete();
await ctx.reply({content: 'Mensaje eliminado correctamente.', ephemeral: true});
} catch (e) {
await ctx.reply({content: `ERROR: No se ha podido eliminar el mensaje, asegúrate que estás usando el ID y el canal correcto.`})
}
},
});

View File

@@ -24,14 +24,18 @@ export default commandModule({
],
//alias : [],
execute: async (ctx, options, message) => {
const userToBan = options[1].getMember('usuario', true);
const reason = options[1].get('razon', true).value;
const kickEmbed = new EmbedBuilder()
.setTitle('Nuevo kick.')
.setDescription(`Kick efectuado por <@${ctx.author}>.\nRazón: ${reason}.`);
userToBan.kick(reason)
const sendToMods = ctx.client.guilds.cache.get('928018226330337280')!.channels.cache.get('1004118323258208257')
await sendToMods.send({content: `Se ha expulsado a ${userToBan}.\nKick efectuado por ${ctx.user} con razón "${reason}."`})
await ctx.reply({content: 'Expulsado correctamente!'})
try {
const userToBan = options[1].getMember('usuario', true);
const reason = options[1].get('razon', true).value;
const kickEmbed = new EmbedBuilder()
.setTitle('Nuevo kick.')
.setDescription(`Kick efectuado por <@${ctx.author}>.\nRazón: ${reason}.`);
userToBan.kick(reason)
const sendToMods = ctx.client.guilds.cache.get('928018226330337280')!.channels.cache.get('1004118323258208257')
await sendToMods.send({content: `Se ha expulsado a ${userToBan}.\nKick efectuado por ${ctx.user} con razón "${reason}."`})
await ctx.reply({content: 'Expulsado correctamente!'})
} catch (e) {
await ctx.reply({content: `ERROR: No puedo hacer este comando porque a lo mejor soy inferior que el rol de esa persona o estoy usándolo contra admins.`})
}
},
});

View File

@@ -13,17 +13,20 @@ export default commandModule({
description: 'Escribe un número',
type: ApplicationCommandOptionType.Number,
required: true,
min_value: 2,
min_value: 1,
max_value: 100
}],
//alias : [],
execute: async (ctx, options) => {
const amount = options[1].getNumber('numero', true);
ctx.channel.bulkDelete(amount, true).catch(err => {
console.error(err);
ctx.reply({content: 'Ha habido un error eliminando mensajes! (mira la consola, Sr Izan)', ephemeral: true});});
await ctx.reply({content: `Se han eliminado ${amount} mensajes.`})
const sendToMods = ctx.client.guilds.cache.get('928018226330337280')!.channels.cache.get('1004118323258208257')
await sendToMods.send({content: `Se han eliminado ${amount} mensajes en ${ctx.channel}\nEfectuado por ${ctx.user}.`})
},
try {
const amount = options[1].getNumber('numero', true);
ctx.channel.bulkDelete(amount, true).catch(err => {
console.error(err);
ctx.reply({content: 'Ha habido un error eliminando mensajes! (mira la consola, Sr Izan)', ephemeral: true});});
await ctx.reply({content: `Se han eliminado ${amount} mensajes.`})
const sendToMods = ctx.client.guilds.cache.get('928018226330337280')!.channels.cache.get('1004118323258208257')
await sendToMods.send({content: `Se han eliminado ${amount} mensajes en ${ctx.channel}\nEfectuado por ${ctx.user}.`})
} catch (e){
ctx.reply({content: 'Ha habido un error eliminando mensajes! Error reportado automáticamente.', ephemeral: true})};
}
});

View File

@@ -24,13 +24,17 @@ export default commandModule({
],
//alias : [],
execute: async (ctx, options) => {
const seconds = options[1].getNumber("segundos", true);
const reason = options[1].getString("razon", true);
try {
const seconds = options[1].getNumber("segundos", true);
const reason = options[1].getString("razon", true);
ctx.channel.setRateLimitPerUser(seconds, reason)
ctx.channel.setRateLimitPerUser(seconds, reason)
ctx.reply({content: `Se han añadido ${seconds} segundos de modo lento al canal de voz actual`})
const sendToMods = ctx.client.guilds.cache.get('928018226330337280')!.channels.cache.get('1004118323258208257')
await sendToMods.send({content: `Se ha aplicado modo lento al canal ${ctx.channel}.\nEfectuado por ${ctx.user} con ${seconds} segundos de retardo.\nRazón: ${reason}`})
ctx.reply({content: `Se han añadido ${seconds} segundos de modo lento al canal de voz actual`})
const sendToMods = ctx.client.guilds.cache.get('928018226330337280')!.channels.cache.get('1004118323258208257')
await sendToMods.send({content: `Se ha aplicado modo lento al canal ${ctx.channel}.\nEfectuado por ${ctx.user} con ${seconds} segundos de retardo.\nRazón: ${reason}`})
} catch (e) {
ctx.reply({content: `No se ha podido aplicar modo lento al canal.`})
}
},
});

View File

@@ -35,14 +35,16 @@ export default commandModule({
],
//alias : [],
execute: async (ctx, options) => {
const usuario = options[1].getMember('usuario', true);
const minutos = options[1].getNumber('minutos', true);
const razon = options[1].getString('razon', true);
const minutosToMilisegundos = minutos * 60 * 1000
usuario.timeout(minutosToMilisegundos, razon).then(() => {ctx.reply({content: `Se ha silenciado a ${usuario} correctamente.`, ephemeral: true})})
const sendToMods = ctx.client.guilds.cache.get('928018226330337280')!.channels.cache.get('1004118323258208257')
await sendToMods.send({content: `Se ha silenciado a ${usuario}.\nSlencio efectuado por ${ctx.user} con ${minutos} minutos de duración.\nRazón: ${razon}`})
}
try {
const usuario = options[1].getMember('usuario', true);
const minutos = options[1].getNumber('minutos', true);
const razon = options[1].getString('razon', true);
const minutosToMilisegundos = minutos * 60 * 1000
usuario.timeout(minutosToMilisegundos, razon).then(() => {ctx.reply({content: `Se ha silenciado a ${usuario} correctamente.`, ephemeral: true})})
const sendToMods = ctx.client.guilds.cache.get('928018226330337280')!.channels.cache.get('1004118323258208257')
await sendToMods.send({content: `Se ha silenciado a ${usuario}.\nSlencio efectuado por ${ctx.user} con ${minutos} minutos de duración.\nRazón: ${razon}`})
} catch (e) {
await ctx.reply({content: `ERROR: No puedo hacer este comando porque a lo mejor soy inferior que el rol de esa persona o estoy usándolo contra admins.`})
}
},
);
});

View File

@@ -8,6 +8,7 @@ require("dotenv").config();
const sernPrefix = process.env.PREFIX
const mongoose = require('mongoose');
const youtube = require('discord-bot-youtube-notifications');
const client = new Client({
intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages, GatewayIntentBits.GuildMembers, GatewayIntentBits.MessageContent, GatewayIntentBits.GuildMembers, GatewayIntentBits.GuildMessageReactions, GatewayIntentBits.GuildVoiceStates],
restTimeOffset: 0

View File

@@ -39,7 +39,7 @@
// "noResolve": true, /* Disallow 'import's, 'require's or '<reference>'s from expanding the number of files TypeScript should add to a project. */
/* JavaScript Support */
// "allowJs": true, /* Allow JavaScript files to be a part of your program. Use the 'checkJS' option to get errors from these files. */
"allowJs": true, /* Allow JavaScript files to be a part of your program. Use the 'checkJS' option to get errors from these files. */
// "checkJs": true, /* Enable error reporting in type-checked JavaScript files. */
// "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from 'node_modules'. Only applicable with 'allowJs'. */