Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
129 views
in Technique[技术] by (71.8m points)

windows - Separating .send and .ban (async) with Visual Studio JavaScript?

Good morning/evening, I'm making a Discord bot. My idea is that it first DMs you, then bans you. I know that both .send and .ban are async, and I need to separate them somehow so that it does .send first, then bans. One interesting thing I've noticed is that it doesn't work the first time, NOT sending a dm before banning, but then it works flawlessly, sending a DM right before banning. How can I make it so that it does the thing first try? Basically, it only works the second time that I ban someone, which isn't exactly perfect, is there a way to go around this?

module.exports = {
    name: 'ban',
    description: 'ban someone',
    execute (message, args, Discord) {
        const member = message.mentions.users.first();
        if (member) {
            const memberTarget = message.guild.members.cache.get(member.id);
            const exampleEmbed = new Discord.MessageEmbed()
                .setColor('#FF4500')
                .setTitle('title')
                .setDescription('description')
                .setFooter('footer')
                .setAuthor('author')
            message.guild.members.cache.get(member.id).send(exampleEmbed);
            memberTarget.ban();
question from:https://stackoverflow.com/questions/66053134/separating-send-and-ban-async-with-visual-studio-javascript

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Thank you for the suggestion, nbokmans. I've come up with a solution myself. I was writing this post in a sleep-deprived state of mine. The solution is much simpler. I just added a timeout.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...