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

385
Views
Discord.js: How do I take everything from an array, and then use every part of the array and react to a message individually?

Here is my current code. I want to, as the title says, take everything from an array then react to a message.

 reactionCount = args.length // how many choices there are
        reactions = [
            '๐Ÿ‡ฆ',
            '๐Ÿ‡ง',
            '๐Ÿ‡จ', 
            '๐Ÿ‡ฉ',
            '๐Ÿ‡ช'
        ] // chosen reactions in an array
        
        let toReact = reactions.split(0, reactionCount) //here i try to get the first [n] reactions. This comes out as an array. This is the array I want to take everything from and then react
        console.log(toReact) //test
        message.react(toReact) //test

Right now this is trying to react to the message with an array. I am aware I can do this individually, kind of like this (old code)

if (args[4]) {
        const sentMessage = await message.channel.send(`**${message.member.displayName} Started a poll!**\n**A)** ${args[0]}\n**B)** ${args[1]}\n**C)** ${args[2]}\n**D)** ${args[3]}\n**E)** ${args[4]}`)
            sentMessage.react('๐Ÿ‡ฆ')
            sentMessage.react('๐Ÿ‡ง')
            sentMessage.react('๐Ÿ‡จ')
            sentMessage.react('๐Ÿ‡ฉ')
            sentMessage.react('๐Ÿ‡ช')
        } else if (args[3]) {
            const sentMessage = await message.channel.send(`**${message.member.displayName} Started a poll!**\n**A)** ${args[0]}\n**B)** ${args[1]}\n**C)** ${args[2]}\n**D)** ${args[3]}`)
            sentMessage.react('๐Ÿ‡ฆ')
            sentMessage.react('๐Ÿ‡ง')
            sentMessage.react('๐Ÿ‡จ')
            sentMessage.react('๐Ÿ‡ฉ')
        } else if (args[2]) {
            const sentMessage = await message.channel.send(`**${message.member.displayName} Started a poll!**\n**A)** ${args[0]}\n**B)** ${args[1]}\n**C)** ${args[2]}`)
            sentMessage.react('๐Ÿ‡ฆ')
            sentMessage.react('๐Ÿ‡ง')
            sentMessage.react('๐Ÿ‡จ')
        } else if (args[1]) {
            const sentMessage = await message.channel.send(`**${message.member.displayName} Started a poll!**\n**A)** ${args[0]}\n**B)** ${args[1]}`)
            sentMessage.react('๐Ÿ‡ฆ')
            sentMessage.react('๐Ÿ‡ง')
        } else if (args[0]) {
            const sentMessage = await message.channel.send(`**${message.member.displayName} Started a poll!**\n**A)** ${args[0]}`)
            sentMessage.react('๐Ÿ‡ฆ')
        } 

But I want to save some space. I want to preface, I am kind of beginner right now, in terms of javascript. I used to be really good, and I could have done this, but I took a year and a half long break and now I am essentially useless.

about 4 years ago ยท Juan Pablo Isaza
1 answers
Answer question

0

Ok...

for (var i = 0; i < reactions.length; i++) {
    var toReact = reactions[i];
    console.log(toReact) //test
    message.react(toReact) //test
}
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!