From 99b1b147cf17cfef61c4f85fab51dda5cbbd1882 Mon Sep 17 00:00:00 2001 From: ale Date: Sun, 20 Jul 2025 12:08:38 +0200 Subject: [PATCH] join-channel Signed-off-by: ale --- README.md | 16 ++++++++++++ index.js | 78 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 94 insertions(+) diff --git a/README.md b/README.md index fd5c90d..6049066 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,7 @@ A powerful Discord bot that can send messages and search for multimedia files on - πŸ“ˆ **Google Trends** - Show current trending topics by country with grouped articles - ⬇️ **File Download** - Download and share multimedia files directly in Discord - 🟠 **Bitcoin Monitor** - Real-time Bitcoin transaction monitoring +- πŸšͺ **Channel Access** - Join and send messages to specific Discord channels by ID ## Installation @@ -93,6 +94,21 @@ Downloads and shares multimedia files directly in Discord. - Automatically cleans up temporary files - Shows file information in rich embeds +### πŸšͺ Join Channel +``` +/join-channel channel-id:768329192131526686 message:Hello from bot! +``` +Makes the bot access and send a message to a specific Discord channel. +- `channel-id`: Discord channel ID (optional, defaults to your specified channel) +- `message`: Custom message to send (optional) + +**Join Channel Features:** +- Access channels by ID across different servers +- Automatic permission checking +- Rich embed with connection information +- Error handling for invalid channels or permissions +- Supports any text-based Discord channel + ## Security Features - βœ… Environment variables for token security diff --git a/index.js b/index.js index 64499e5..f8ac3dc 100644 --- a/index.js +++ b/index.js @@ -164,6 +164,24 @@ client.on(Events.ClientReady, async readyClient => { ] } ] + }, + { + name: 'join-channel', + description: 'Make the bot access a specific Discord channel', + options: [ + { + name: 'channel-id', + type: 3, // STRING type + description: 'Discord channel ID (e.g., 768329192131526686)', + required: false + }, + { + name: 'message', + type: 3, // STRING type + description: 'Message to send to the channel', + required: false + } + ] } ]; @@ -1045,6 +1063,66 @@ client.on(Events.InteractionCreate, async interaction => { } break; + case 'join-channel': + await interaction.deferReply({ ephemeral: true }); + const channelId = interaction.options.getString('channel-id') || '768329192131526686'; // Default to your channel + const channelMessage = interaction.options.getString('message') || 'πŸ€– Β‘Hola! El bot ahora tiene acceso a este canal.'; + + try { + // Try to fetch the channel by ID + const targetChannel = await client.channels.fetch(channelId); + + if (!targetChannel) { + await interaction.editReply('❌ No se pudo encontrar el canal. Verifica que el ID sea correcto y que el bot tenga acceso al servidor.'); + return; + } + + if (!targetChannel.isTextBased()) { + await interaction.editReply('❌ El canal especificado no es un canal de texto.'); + return; + } + + // Check if bot has permission to send messages in that channel + if (!targetChannel.permissionsFor(client.user).has('SendMessages')) { + await interaction.editReply('❌ El bot no tiene permisos para enviar mensajes en ese canal.'); + return; + } + + // Send message to the target channel + const embed = new EmbedBuilder() + .setTitle('πŸ€– Bot Conectado') + .setDescription(channelMessage) + .addFields( + { name: 'πŸ“ Canal', value: `${targetChannel.name} (${targetChannel.id})`, inline: true }, + { name: '🏠 Servidor', value: targetChannel.guild.name, inline: true }, + { name: '⏰ Conectado', value: ``, inline: true } + ) + .setColor(0x00FF00) + .setTimestamp() + .setFooter({ text: 'Bot Discord Multimedia' }); + + await targetChannel.send({ embeds: [embed] }); + + await interaction.editReply(`βœ… ‘Éxito! El bot ha accedido al canal **${targetChannel.name}** en el servidor **${targetChannel.guild.name}** y ha enviado un mensaje.`); + + } catch (error) { + console.error('Error accessing channel:', error); + let errorMessage = '❌ Error al acceder al canal: '; + + if (error.code === 10003) { + errorMessage += 'Canal no encontrado. Verifica que el ID sea correcto.'; + } else if (error.code === 50001) { + errorMessage += 'El bot no tiene acceso a este canal o servidor.'; + } else if (error.code === 50013) { + errorMessage += 'El bot no tiene permisos suficientes.'; + } else { + errorMessage += error.message; + } + + await interaction.editReply(errorMessage); + } + break; + case 'btc-monitor': const action = interaction.options.getString('action'); const channel = interaction.options.getChannel('channel');