Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
127 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 Reply

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...