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 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…