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

165
Vistas
Discord.js Sorting Array Of Objects glitching text

I have this code where I shuffle an array, and display the first 16 values in a discord.js embed:

const items = require('../schemas/gameSchema');
const items0 = await items.find();
var shuffle = require('shuffle-array');

const items1 = shuffle(items0);

const lb = items1
  .slice(0)
  .map(
    ({ DepositAmount, BetAmount, GameName, TotalPlays }, pos) =>
      `**${GameName}** \n Initial Deposit Amount: **${commaNumber(
        DepositAmount,
      )}** <:bob:809551218217058354> \n Bet Amount:  **${commaNumber(
        BetAmount,
      )}** <:bob:809551218217058354> \n Total Game Plays : ${commaNumber(
        TotalPlays,
      )} 🕹 \n `,
  )
  .join('\n');
const lbnewnew = lb.slice(15);
const newlb = lbnewnew.toString();
let exampleEmbed = new Discord.MessageEmbed()
  .setColor('RANDOM')
  .setTitle('Discover Games')
  .setDescription(`${newlb}`)

  .setTimestamp()
  .setFooter(`You can play games with /game play <game name>`);

await interaction.reply({ embeds: [exampleEmbed] });

Here is the gameSchema (defined in items constant)

const mongoose = require('mongoose')

const adSchema = mongoose.Schema({
    User:String,
    Funds:Number,
    ProfitToClaim:Number,
    TotalProfit:Number,
    TotalLoss:Number,
    DepositAmount:Number,
    BetAmount:Number,
    TotalPlays:Number,
    TotalWins:Number,
    TotalLosses:Number,
    GameName:String,
    GameDescription:String,

})
module.exports = mongoose.model('NewGames', adSchema, 'NewGames')

Everything that I am taking from the schema is defined, but when I run this command, the first element displayed has a broken name with some random letters

enter image description here

or like this enter image description here

There is no game called em or ial in the database, so I am not sure why this is happening

enter image description here

How do I stop it from saying random characters and not displaying the first element's game name? And why is this happening?

about 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

It's because you're slicing off the first 15 characters (i.e. lb.slice(15)). Instead, you should keep the first 15 results of items1. You also don't need all those toStrings and template literals.

const description = items1
  .slice(0, 15)
  .map(
    ({ DepositAmount, BetAmount, GameName, TotalPlays }, pos) =>
      `**${GameName}** \n Initial Deposit Amount: **${commaNumber(
        DepositAmount,
      )}** <:bob:809551218217058354> \n Bet Amount:  **${commaNumber(
        BetAmount,
      )}** <:bob:809551218217058354> \n Total Game Plays : ${commaNumber(
        TotalPlays,
      )} 🕹 \n `,
  )
  .join('\n');

let exampleEmbed = new Discord.MessageEmbed()
  .setColor('RANDOM')
  .setTitle('Discover Games')
  .setDescription(description)
  .setTimestamp()
  .setFooter(`You can play games with /game play <game name>`);

await interaction.reply({ embeds: [exampleEmbed] });
about 4 years ago · Santiago Trujillo 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