#Code sending duplicated

20 messages · Page 1 of 1 (latest)

errant forge
#

Hey guys, withy code right here, from line around !live command (last lines of code), when i use the command, my code just sends me duplicated if the objects in the json file, I made sure the json file is perfect, so the problem is the code, can anyone help.


import { discordSort, messageLink } from "discord.js";
import { Client, GatewayIntentBits, EmbedBuilder, SlashCommandBuilder } from "discord.js"
const client = new Client(
    {
        intents: [
          GatewayIntentBits.Guilds,
          GatewayIntentBits.GuildMessages,
          GatewayIntentBits.GuildMembers,
          GatewayIntentBits.MessageContent
        ]
    }
)



var liveEmbed;


// @ts-ignore
import IFL from "iflive"
// @ts-ignore

IFL.init('hidden', {"enableLog": true, "loggingLevel": 1, "callback": true});

// embeds










const ranksEmbed = new EmbedBuilder()
.setColor('#E0050B')

const siteEmbed = new EmbedBuilder()
.setColor('#E0050B')
.setTitle('Avianca Virtual Website')
.setURL('https://ifaviancavirtual.com')
.setAuthor({ name: 'Avianca Virtual', iconURL: 'https://media.discordapp.net/attachments/948687532365869108/995388756301463552/761D13FB-12BE-4FA6-A53D-9335196D5469.jpg', url: 'https://discord.js.org' })
.setFooter({ text: 'Generated by the Avianca Virtual Official Assistant Bot'});

const ccEmbed = new EmbedBuilder()
.setColor('#E0050B')

const routesEmbed = new EmbedBuilder()

const multipliersEmbed = new EmbedBuilder()
.setColor('#E0050B')

const helpEmbed = new EmbedBuilder()
.setColor('#E0050B')



// @ts-ignore
// @ts-ignore
const channel = client.channels.cache.find(channel => channel.name === "general");

client.on("ready", () => {
  console.log(`Logged in as ${client.user.tag}!`)
})



// create channel when member joins


// welcome message in general


// commands

  
    msg.reply({ embeds: [ticketEmbed] });
  } else if (msg.content.startsWith(prefix) && msg.content.includes("please")) {
    msg.reply("Please?");
  }
})


client.on('messageCreate', msg => {
  if (msg.content.startsWith(prefix) && msg.content.includes("userStats")) {
      const name = msg.content.slice("!userStats".length).trim().split(' ');
  IFL.call("users", {}, {discourseNames: name}, (data) => { 
      const flightTime = data[0].flightTime/60
      const hours = flightTime.toFixed(0) 
    const statsEmbed = new EmbedBuilder()
    .setColor('#E0050B')
    .setTitle('Here are the ranks for ' + "**" + name + "**")

    msg.reply({ embeds: [statsEmbed] })
})}})

IFL.call("flights", { sessionId: "7e5dcd44-1fb5-49cc-bc2c-a9aab1f6a856" }, {});

// @ts-ignore
IFL.call("sessions", {}, {}, (seshData) => {
  
})

client.on("messageCreate", msg => {
if (msg.content.startsWith(prefix) && msg.content.includes("live")) {


IFL.call("sessions", {}, {}, (sessionData) => {
  IFL.call("flights", {sessionId: "7e5dcd44-1fb5-49cc-bc2c-a9aab1f6a856"}, {}, (data) => {
    msg.channel.send("Here are the pilots that are flying at this moment:")
    for(var i=0 ; i < data.length ; i++ ){
      var last2 = (data[i].callsign?.slice(-2).toString())
      // @ts-ignore
 
      
        if (last2 === "AK") {
        liveEmbed = new EmbedBuilder()
    .setTitle("Flights:")
    .setAuthor({ name: "callsign", iconURL: 'https://media.discordapp.net/attachments/948687532365869108/995388756301463552/761D13FB-12BE-4FA6-A53D-9335196D5469.jpg', url: 'https://discord.js.org' })
    .setColor('#E0050B')
    .addFields(
      {name: "Username:", value: data[i].username},
      {name: "Callsign:", value: data[i].callsign},
      {name: "Altitude:", value: data[i].altitude.toFixed(0) + "ft"},
      {name: "Speed:", value: data[i].speed.toFixed(0) + "kts"}
      
    )
    
          
        } 
        msg.channel.send({ embeds: [liveEmbed] });
    } 
    
    
  }
)
})
}
})

client.login("hidden")

ivory blazeBOT
#

• What's your exact discord.js npm list discord.js and node node -v version?
• Post the full error stack trace, not just the top part!
• Show your code!
• Explain what exactly your issue is.
• Not a discord.js issue? Check out #useful-servers.

errant forge
#

Anyone

ivory blazeBOT
#

Codeblocks:
```js
const Discord = require("discord.js");
// further code
```
becomes

const Discord = require("discord.js"); 
// further code

Inline Code:
`console.log('inline!');` becomes console.log('inline!');

errant forge
#

i’ve deleted some code because of discord limitations, i have that there

uncut glen
#

Or use a bin

ivory blazeBOT
#

To share long code snippets use a service like gist, sourcebin, starbin, or similar instead of posting them as large code blocks.

errant forge
#

oh ok

errant forge
#

so anyone free to help please?

mental spire
#

If you‘d actually do what you got told so your code becomes readable, sure

mental spire
#

You somehow used two different types of backticks there making the codeblock render as inline… and the size of that code would be way easier to read in a pastebin anyway

errant forge
#

@mental spire i can send you a pastebin later today, but can you see anything rn?

mental spire
#

add some console.log in there to find out what gets called twice... is it the messageCreate event itself, one of the callbacks you have there, ...

errant forge
mental spire
#

Then why ping me if you didn’t do it yet? Did you really make me come here to see there’s nothing new…

errant forge