I want to create a command that create an announcement which is carried out in several stages. First, I type *annonce channelID then the bot asks me for the title, then the message (in theory)
Unfortunately, once *annonce channelID typed, the bot does not continue and writes this (it does the .catch)
Can you help me ?
Bot react : Entre le titre de ton annonce : title error msg error react error
const Discord = require('discord.js');
const delay = require('delay');
const NO = '❌';
const YES = '✅';
module.exports.run = async(bot, message, args) => {
const userN = message.member;
const msgFilter = m => m.author.id === message.author.id;
const userDepotAnnonce = message.author.username;
if(!message.member.hasPermission('ADMINISTRATOR')) {return message.channel.send("Vous ne pouvez pas passer d'annonces !");}
const channelID = args[0];
let sendchannel = bot.channels.get(channelID);
if(message.content !== `*annonce ${channelID}`) {return message.channel.send('Utilise ***annonce ``channelID``** puis valide');}
message.channel.send("Entre le titre de ton annonce :");
await delay(100);
message.channel.awaitMessages(msgFilter, { max: 1, time: 15000, errors: ['time'] })
.then(titleCollected => {
const msgTitle = titleCollected.first().content;
message.channel.send("Entrez le contenu de l'annonce et joint ton fichier :");
})
.catch(titleCollected => {
message.channel.send('*title error*');
console.log('Pas de titre');
})
message.channel.awaitMessages(msgFilter, { max: 1, time: 30000, errors: ['time'] })
.then(msgCollected => {
const messageToSend = msgCollected.first().content;
if(message.attachments.size > 0){
let attachment = message.attachments.first()
const url = attachment.url
var annonceFinal = new Discord.RichEmbed()
.setColor("03CD43")
.setTitle(`Nouvelle annonce : **${msgTitle}**`)
.setAuthor(userDepotAnnonce, message.author.avatarURL, url)
.addField('Annonce', messageToSend)
.addField('Lien', url)
.setFooter("Annonces by PDC")
}
else{
var annonceFinal = new Discord.RichEmbed()
.setColor("03CD43")
.setTitle(`Nouvelle annonce : **${msgTitle}**`)
.setAuthor(userDepotAnnonce, message.author.avatarURL)
.addField('Annonce', messageToSend)
.setFooter("annonces by pdc")
}
message.channel.send(`Vous vous désirez passer l'annonce **${msgTitle}** contenant **${messageToSend}** dans ${sendchannel}.\nPour confirmer, utilisez les reactions.` +YES +NO);
})
.catch(msgCollected => {
message.channel.send('*msg error*');
console.log('Pas de message');
})
const filter = (reaction, user) => {return ['✅', '❌'].includes(reaction.emoji.name) && user.id === message.author.id;};
message.react('✅').then(() => message.react('❌'));
message.awaitReactions(filter, { max: 1, time: 10000, errors: ['time'] })
.then(collected => {
const reaction = collected.first();
if (reaction.emoji.name === '✅'){
sendchannel.send(annonceFinal)
}
else if (reaction.emoji.name === '❌'){
message.channel.send('Alors arrête de me faire chier !');
}
})
.catch(collected => {
message.channel.send('*react error*');
console.log('*react error*');
})
};
module.exports.help = {
name: 'annonce'
};