缺少.then但在哪里放置idk

时间:2020-05-02 20:53:15

标签: javascript if-statement bots discord.js

所以我认为我完全忘记了一些。那是因为该机器人会立即发送B表情符号消息,而不会引起用户的反应,即使我提供“建议”,它也不会将其发送到特定频道,但是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 个答案:

答案 0 :(得分:2)

我建议学习等待/异步功能。 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;
}

这只是其中的一部分,但是您应该能够掌握要点...