Quiero que mi bot registre mensajes de una identificación específica o, si no es posible, registrar todos los mensajes de DM y enviarlos a un canal de servidor de discordia. Si una identificación específica envía '¡Hola!', el bot enviará '¡Hola!' al ID de canal especificado.
Si tiene todas las intenciones requeridas habilitadas, simplemente puede escuchar messageCreate ( message para DiscordJS v12 y versiones anteriores) y verificar el tipo de canal del que proviene su mensaje. Por ejemplo:
const { Client, Intents } = require('discord.js'); // Initializing your client const client = new Client({ intents: [ // Intent for catching direct messages Intents.DIRECT_MESSAGES, // Intents for interacting with guilds Intents.GUILDS, Intents.GUILD_MESSAGES ] }); // Subscribe to the messages creation event client.on('messageCreate', async (message) => { // Here you check for channel type // We only need direct messages here, so skip other messages if (message.channel.type !== 'DM') return; // Now we need guild where we need to log these messages // Note: It's better for you to fetch this guild once and store somewhere // and do not fetch it on every new received message const targetGuild = await client.guilds.fetch('YOUR GUILD ID'); // Here you getting the channel from the list of the guild channels const targetLoggingChannel = await targetGuild.channels.fetch('LOGGING CHANNEL ID'); // Sending content of the message to the target channel // You can also cover the message into embed with some additional // information about sender or time this message was sent await targetLoggingChannel.send(message.content); }); // Authorizing client.login('TOKEN HERE');Este es un ejemplo mínimo de cómo registrar mensajes de los DM del bot en algún canal en cualquier gremio que desee. También debe verificar el canal de registro y la existencia del gremio para evitar errores. También asegúrese de que el bot pueda enviar mensajes al canal de destino.