отсутствует .по но идк, куда поставить - PullRequest
0 голосов
/ 02 мая 2020

Так что я думаю, что я совсем забыл. Затем, потому что бот отправляет сообщение B emoji мгновенно без реакции пользователя, и даже когда я предоставлю «предложение», он не отправит его на указанный канал c, но idk, где я должен положить недостающие. Может кто-то мне помочь, пожалуйста? Я пытался понять это сам и испытал кое-что, но ничего лучше не получилось.

execute(message, client, args) {
        const Discord = require('discord.js');

        let Embed = new Discord.MessageEmbed()
            .setColor('0x0099ff')
            .setDescription(`Suggestion categories`)
            .addField(`For what you want to suggest something?`, `\nA: I want to suggest something for the Website/Servers/Discord Server\nB: I want to suggest something for the CloudX Bot \n\nPlease react to this message with A or B`)

        message.channel.send(Embed).then(function (message) {
            message.react("?").then(() => {
                message.react("?")
            const filter = (reaction, user) => {
                return ['?', '?'].includes(reaction.emoji.name) && user.id;
        }

        message.awaitReactions(filter, { max: 1 })
                .then(collected => {
                    const reaction = collected.first();


                    if (reaction.emoji.name === '?') {
                        const filter = m => m.author.id === message.author.id;

                        message.channel.send(`Please provide a suggestion for the Website/Servers/Discord Server or cancel this command with "cancel"!`).then(() => {

                        message.channel.awaitMessages(filter, { max: 1, })
                            .then(async (collected) => {
                                if (collected.first().content.toLowerCase() === 'cancel') {
                                    message.reply("Your suggestion has been cancelled.")
                                }
                                else {
                                    let embed1 = new Discord.MessageEmbed()
                                        .setColor('0x0099ff')
                                        .setAuthor(message.author.tag)
                                        .addField(`New Suggestion:`, `${collected.first().content}`)
                                        .setFooter(client.user.username, "attachment://CloudX.png")
                                        .setTimestamp();

                                    const channel = await client.channels.fetch("705781201469964308").then(() => {
                                    channel.send({embed: embed1, files: [{
                                        attachment:'CloudX.png',
                                        name:'CloudX.png'
                                        }]})

                                    message.channel.send(`Your suggestion has been filled to the staff team. Thank you!`)
                                    })
                                } 
                        })
                        })
                    }
                    if (reaction.emoji.name === '?') {
                        const filter = m => m.author.id === message.author.id;

                        message.channel.send(`Please provide a suggestion for the CloudX Bot or cancel this command with "cancel"!`).then(() => {

                        message.channel.awaitMessages(filter, { max: 1, })
                            .then(async (collected) => {
                                if (collected.first().content.toLowerCase() === 'cancel') {
                                    message.reply("Your suggestion has been cancelled.")
                                }
                                else {
                                    let embed2 = new Discord.MessageEmbed()
                                        .setColor('0x0099ff')
                                        .setAuthor(message.author.tag)
                                        .addField(`New Suggestion:`, `${collected.first().content}`)
                                        .setFooter(client.user.username, "attachment://CloudX.png")
                                        .setTimestamp();

                                    const channel = await client.channels.fetch("702825446248808519").then(() => {
                                    channel.send({embed: embed2, files: [{
                                        attachment:'CloudX.png',
                                        name:'CloudX.png'
                                        }]})

                                    message.channel.send(`Your suggestion has been filled to the staff team. Thank you!`)
                                    })
                                } 
                        })
                        })
                    }    
                })
            })
        })
    },

1 Ответ

2 голосов
/ 03 мая 2020

Я бы предложил изучить функции await / asyn c. https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Asynchronous/Async_await

Это очистит ваш код и сохранит стабильность без пяти тысяч .then()

async execute(message, client, args) {
    const { MessageEmbed } = require('discord.js');
    const embed = new MessageEmbed()
    .setColor('#0099ff')
    .setDescription(`Suggestion categories`)
    .addField(`For what you want to suggest something?`, `\nA: I want to suggest something for the Website/Servers/Discord Server\nB: I want to suggest something for the CloudX Bot \n\nPlease react to this message with A or B`)

    const question = message.channel.send(embed)
    await question.react("?")
    await question.react("?")

    const filter = (reaction, user) => {
    return ['?', '?'].includes(reaction.emoji.name) && user.id;
}

Это только часть этого, но вы должны быть в состоянии получить суть ...

...