Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

190
Vistas
Discord.js Envía un mensaje cada X segundos con Client.on('ready', () => { });

Me gustaría enviar un mensaje cada X segundos y que el usuario que reaccione primero le de 10 monedas.

El problema no viene del sistema de monedas, está correctamente ejecutado.

Este código no funciona y me dice que Cannot read properties of undefined (reading 'send')

Sé que esto se debe a que no estoy usando ready Client.on('message', message => { }) pero realmente me gustaría que pasara, ¿hay alguna forma de hacerlo de manera diferente? ¿Me pueden ayudar a corregir este código?

 Client.on('ready', () => { const fs = require('fs'); const userCoin = JSON.parse(fs.readFileSync('Storage/userCoin.json', 'utf-8')); const channel2up22 = Client.channels.cache.get('935549530210983976'); //Random Drop const doSomething = () => { let Embed = new Discord.MessageEmbed() .setTitle("Wild Gift 🎁 ! | GuinGame - v2.0 🎰") .setColor('#caabd0') .setDescription("Be the **first** to react ``'🚀'`` to this message to win **10 🪙!**") .setThumbnail("https://media.giphy.com/media/Jv1Xu8EBCOynpoGBwd/giphy.gif") .setFooter(text="🤖 GuinbearBot | 🌐 Guinbeargang.io") .setTimestamp() channel2up22.send(Embed) .then(message => { message.react('🚀'); Client.on('messageReactionAdd', (reaction, user) => { if (reaction.emoji.name === '🚀' && user.id == "338621907161317387") { message.delete(); var Magic09 = 1; while (Magic09 <= 10) { userCoin[user.id].CoinsAmount++; Magic09++; } fs.writeFile('Storage/userCoin.json', JSON.stringify(userCoin), (err) => {if (err) console.error(err);}) let Embed = new Discord.MessageEmbed() .setTitle("Wild Gift 🎁 ! | GuinGame - v2.0 🎰") .setColor('#caabd0') .setDescription("<@"+ user.id + "> has won the **Wild Gift 🎁 !**") .setThumbnail("https://media.giphy.com/media/Jv1Xu8EBCOynpoGBwd/giphy.gif") .setFooter(text="🤖 GuinbearBot | 🌐 Guinbeargang.io") .setTimestamp() channel2up22.send(Embed) } }) }).catch(console.error); } setInterval(doSomething(), 5000) }) //Random Drop });
about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

No puedo probar completamente este código, pero debería funcionar suponiendo que todo este código se incluya en un solo archivo. Si obtiene errores o algo, comente a continuación y veré qué puedo hacer para ayudar.

 // Near top of file but after you have defined your client with const Client = new Discord.Client() const fs = require('fs') const Discord = require('discord.js') const Client = new Discord.Client ({ intents: /*your intents here*/, }) const guild = Client.guilds.cache.get('935549530210983976') const channel2up22 = guild.channels.cache.get('935549530210983976'); // channels are an element of the guild not the client const userCoin = JSON.parse(fs.readFileSync('Storage/userCoin.json', 'utf-8')); // placing the function outside of a listener and can be called at anytime function doSomething() { const Embed = new Discord.MessageEmbed() .setTitle("Wild Gift 🎁 ! | GuinGame - v2.0 🎰") .setColor('#caabd0') .setDescription("Be the **first** to react ``'🚀'`` to this message to win **10 🪙!**") .setThumbnail("https://media.giphy.com/media/Jv1Xu8EBCOynpoGBwd/giphy.gif") .setFooter({ text: "🤖 GuinbearBot | 🌐 Guinbeargang.io" }) .setTimestamp() channel2up22.send({ embeds: [Embed] }).then(message => { message.react('🚀'); }).catch(console.error); } Client.on('ready', () => { setInterval(doSomething(), 5000) // every 5 seconds }) // you want to avoid nesting listeners if at all possible Client.on('messageReactionAdd', async (reaction, user) => { if (reaction.message.channel.id === channel2up22) { if (reaction.emoji.name === '🚀' && user.id === "338621907161317387") { // only lets one user react reaction.message.delete(); var Magic09 = 1; while (Magic09 <= 10) { userCoin[user.id].CoinsAmount; Magic09++; } fs.writeFile('Storage/userCoin.json', JSON.stringify(userCoin), (err) => { if (err) console.error(err); }) const Embed = new Discord.MessageEmbed() .setTitle("Wild Gift 🎁 ! | GuinGame - v2.0 🎰") .setColor('#caabd0') .setDescription(`${user} has won the **Wild Gift 🎁 !**`) .setThumbnail("https://media.giphy.com/media/Jv1Xu8EBCOynpoGBwd/giphy.gif") .setFooter({ text: "🤖 GuinbearBot | 🌐 Guinbeargang.io" }) .setTimestamp() channel2up22.send({ embeds: [Embed] }) } } })
about 4 years ago · Juan Pablo Isaza Denunciar

0

Aquí está mi código después de sus primeras modificaciones,

Ahora recibí un error: Uncaught TypeError TypeError: Cannot read properties of undefined (reading 'channels') on the line : const channel2up22 = guild.channels.cache.get('935549530210983976');

 const Discord = require("discord.js"); const Client = new Discord.Client; const fs = require('fs') const guild = Client.guilds.cache.get('925830522138148976'); const channel2up22 = guild.channels.cache.get('935549530210983976'); const userCoin = JSON.parse(fs.readFileSync('Storage/userCoin.json', 'utf-8')); function doSomething() { const Embed = new Discord.MessageEmbed() .setTitle("Wild Gift 🎁 ! | GuinGame - v2.0 🎰") .setColor('#caabd0') .setDescription("Be the **first** to react ``'🚀'`` to this message to win **10 🪙!**") .setThumbnail("https://media.giphy.com/media/Jv1Xu8EBCOynpoGBwd/giphy.gif") .setFooter({ text: "🤖 GuinbearBot | 🌐 Guinbeargang.io" }) .setTimestamp() channel2up22.send({ embeds: [Embed] }).then(message => { message.react('🚀'); }).catch(console.error); } Client.on('ready', () => { setInterval(doSomething(), 5000) }); Client.on('messageReactionAdd', async (reaction, user) => { if (reaction.message.channel.id === channel2up22) { if (reaction.emoji.name === '🚀' && user.id === "338621907161317387") { reaction.message.delete(); var Magic09 = 1; while (Magic09 <= 10) { userCoin[user.id].CoinsAmount; Magic09++; } fs.writeFile('Storage/userCoin.json', JSON.stringify(userCoin), (err) => { if (err) console.error(err); }) const Embed = new Discord.MessageEmbed() .setTitle("Wild Gift 🎁 ! | GuinGame - v2.0 🎰") .setColor('#caabd0') .setDescription(`${user} has won the **Wild Gift 🎁 !**`) .setThumbnail("https://media.giphy.com/media/Jv1Xu8EBCOynpoGBwd/giphy.gif") .setFooter({ text: "🤖 GuinbearBot | 🌐 Guinbeargang.io" }) .setTimestamp() channel2up22.send({ embeds: [Embed] }) } } });

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda