Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

175
Views
El ganador del sorteo sale como indefinido
 const ms = require('ms'); const { MessageEmbed } = require('discord.js') module.exports = { name: 'giveaway', description: 'start a giveaway', async execute(client, message, cmd, args, Discord){ let author = message.author.username; var time; time = args[0]; let title = args.join(" ").slice(3); if(!message.member.permissions.has(['ADMINISTRATOR'])){ message.channel.send(`Sorry **${author}** But you don't have enough permissions to use this command!`) } else { if(message.member.permissions.has(['ADMINISTRATOR'])){ let giveawayEmbed = new MessageEmbed() .setColor('BLACK') .setThumbnail(`${message.author.displayAvatarURL()}`) .setTitle(`${author}'s Giveaway 🎉`) .setDescription(`**${title}**`) .addField(`Duration :`, ms(ms(time), { long: true }), true) .setFooter("React to this message with 🎉 to participate !") var giveawaySent = await message.channel.send({ embeds: [giveawayEmbed] }); giveawaySent.react('🎉'); console.log(giveawaySent.id) setTimeout(async function(){ const react = await giveawaySent.reactions.cache.find(r => r.emoji.name === '🎉').users.fetch(); let index = Math.map(Math.random() * react.length); let winner = react[index]; console.log(react) console.log(index) console.log(winner) let winnerEmbed = new MessageEmbed() .setColor('GREEN') .setDescription(`Congratulations **${winner}** you won **${title}**`) message.reply({ embeds: [winnerEmbed] }) }, ms(time)) } } } }

Estoy tratando de codificar un módulo de obsequio, sin embargo, el resultado ganador aparece como indefinido y parece que no puedo entender por qué. Si pueden ayudarme, se los agradecería mucho.

Estos fueron registrados por la consola si ayuda a cualquier índice = ganador de NaN = indefinido

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

 const ms = require('ms'); const { MessageEmbed } = require('discord.js') module.exports = { name: 'giveaway', description: 'start a giveaway', async execute(client, message, cmd, args, Discord){ let author = message.author.username; var time; time = args[0]; let title = args.join(" ").slice(3); if(!message.member.permissions.has(['ADMINISTRATOR'])){ message.channel.send(`Sorry **${author}** But you don't have enough permissions to use this command!`) } else { if(message.member.permissions.has(['ADMINISTRATOR'])){ let giveawayEmbed = new MessageEmbed() .setColor('BLACK') .setThumbnail(`${message.author.displayAvatarURL()}`) .setTitle(`${author}'s Giveaway 🎉`) .setDescription(`**${title}**`) .addField(`Duration :`, ms(ms(time), { long: true }), true) .setFooter("React to this message with 🎉 to participate !") var giveawaySent = await message.channel.send({ embeds: [giveawayEmbed] }); giveawaySent.react('🎉'); console.log(giveawaySent.id) setTimeout(async function(){ const react = await giveawaySent.reactions.cache.find(r => r.emoji.name === '🎉').users.fetch(); const reactArray = react.map(c => c) let index = Math.floor(Math.random() * reactArray.length); let winner = reactArray[index]; console.log(reactArray) // console.log(react) console.log(index) console.log(winner) let winnerEmbed = new MessageEmbed() .setColor('GREEN') .setDescription(`Congratulations **${winner}** you won **${title}**`) message.reply({ embeds: [winnerEmbed] }) }, ms(time)) } } } }

Parece haber resuelto el problema, se agregó const reactArray = react.map(c => c)

Cambiado let index = Math.floor(Math.random() * react.length); let index = Math.floor(Math.random() * reactArray.length); lo que hizo que const react = await giveawaySent.reactions.cache.find(r => r.emoji.name === '🎉').users.fetch(); en una matriz de ID de usuario

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!