discordjs / discord.js

A powerful JavaScript library for interacting with the Discord API
https://discord.js.org
Apache License 2.0
25.36k stars 3.97k forks source link

Chains/Functions not sending messages after collecting messages #6477

Closed bobsilowski closed 3 years ago

bobsilowski commented 3 years ago

Please describe the problem you are having in as much detail as possible: I have a command which is triggered by a button, the first question sends but then despite me answering it (or anyone else) the bot refuses to store and then send the next question, I have tried using different methods to overcome this but it hasn't worked since I changed to V13. Include a reproducible code sample here, if possible: const { MessageActionRow, MessageButton } = require('discord.js'); const Discord = require('discord.js') const { client } = require('../sweats-united.js') const close = new MessageActionRow() .addComponents( new MessageButton() .setCustomId('close') .setLabel('Close') .setStyle('PRIMARY') .setEmoji('πŸ”’'), );

const options = new MessageActionRow() .addComponents( new MessageButton() .setCustomId('delete') .setLabel('Delete') .setStyle('PRIMARY') .setEmoji('β›”'), new MessageButton() .setCustomId('transcript') .setLabel('Transcript') .setStyle('PRIMARY') .setEmoji('πŸ—’οΈ'), );

client.on('interactionCreate', async (interaction, user) => { if (interaction.customId === "staffapp") { const config = { "token": "ODY5MzE1MTExNjMyOTAwMTY2.YP8ayQ.KMiR4Z8HdqM8ESPn9CxUZXCUN0o", // I have regenerated the token so don't worry about it being leaked "prefix": ".",

"apply_channel_id": `${interaction.channel.id}`,
"finished_applies_channel_id": `${interaction.channel.id}`,

"QUESTIONS": [
    "What is your minecraft username?",
    "How old are you?",
    "What is your timezone?",
    "Are you able to record gameplay?",
    "Do you have a mic to communicate via voice chat?",
    "When did you first join our server?",
    "How much time do you have to contribute to our server daily?",
    "What server do you play the most, as in Skyblock, Factions, Survival, Creative, etc. (Max 150 words)",
    "Have you been previously banned or muted? If so, please explain why (Max 150 words)",
    "Do you have any previous staff experience? If so, elaborate (Provide proof) (Max 150 words)",
    "How will your presence benefit our staff team and server? Is there anything in particular that you believe that you can help improve? (Max 150 words)",
    "Have you made any previous applications in the past for our server? (If so please link)",
    "Are you currently staff on any other server? (Provide proof)",
    "Do you have an issue with a staff member that will stop you from working with them? (Max 150 words)",
    "How well do you understand the rules?",
    "Do you understand that your application may take a while to obtain a response and asking about your application will result in immediate denial of your application?",
    "Would you like to submit your application?"
]

}

  interaction.reply({ content: 'Opening a ticket...', ephemeral: true})
        let c = await interaction.guild.channels.create(`staff app ${interaction.user.username}`, {
    permissionOverwrites: [
    {
      id: interaction.guild.roles.everyone,
      deny: ["VIEW_CHANNEL"],
    },
    {
      id: '877607968378601502',
      allow: ["VIEW_CHANNEL", "SEND_MESSAGES", "READ_MESSAGE_HISTORY"],
    },
    {
      id: interaction.user.id,
      allow: ["VIEW_CHANNEL", "SEND_MESSAGES", "READ_MESSAGE_HISTORY"],
    },
  ],
  type: "text",
  parent: "867825500708405258",
});
await c.send({ content: `Welcome <@${interaction.user.id}>\nYou have started a staff application, answer all of the questions to the best of your ability and then we will reply to you with our thoughts/decisions.`, components: [close]})

let guild = await interaction.guild.fetch();
    let channel_tosend = guild.channels.cache.get(config.finished_applies_channel_id);
    if(!channel_tosend) return console.log("RETURN FROM !CHANNEL_TOSEND");
    const answers = [];
    let counter = 0;

    ask_question(config.QUESTIONS[counter]);

    function ask_question(qu){
        if(counter === config.QUESTIONS.length) return send_finished();
        c.send(qu).then(msg => {
            msg.channel.awaitMessages(m=>m.author.id === user.id, {max: 1, time: 60000, errors: ["time"]}).then(collected => {
                answers.push(collected.first().content);
                ask_question(config.QUESTIONS[++counter]);
            })
        })
    }
    function send_finished(){
        let embed = new Discord.MessageEmbed()
        .setColor("WHITE")
        .setTitle("A new application from: " + user.tag)
        .setDescription(`${user}  |  ${new Date()}`)
        .setFooter(user.id, user.displayAvatarURL({dynamic:true}))
        .setTimestamp()
        for(let i = 0; i < config.QUESTIONS.length; i++){
            try{
                embed.addField(config.QUESTIONS[i], String(answers[i]).substr(0, 1024))
            }catch{
            }
        }
        channel_tosend.send({ embeds: [embed]});
        user.send("Thanks for applying" + message.guild.name)
    }

// Place your code here

Further details:

iCrawl commented 3 years ago

The issue tracker is only for bug reports and enhancement suggestions. If you have a question, please ask it in the Discord server instead of opening an issue – you will get redirected there anyway.