const Discord = require(`discord.js`);
const client = new Discord.Client();
const Long = require(`long`); // INSTALlATION OBLIGATOIRE !!
const token = `TOKEN`;
const prefix = `+`;
client.on(`ready`, () => {
return console.log(`${client.user.username} est en ligne !`);
});
client.on(`message`, async (message) => {
if (message.author.bot) return;
if (message.content.indexOf(prefix) != 0) return;
const args = message.content.slice(prefix.length).trim().split(/ +/g);
const command = args.shift().toLowerCase();
if (command == `public-message`) {
if (!args[0]) {
const embed = new Discord.MessageEmbed()
.setColor(`#0099FF`)
.setAuthor(message.author.username, message.author.displayAvatarURL({
dynamic: true
}))
.setTitle(`Vous devez spécifiez un message !`)
.setTimestamp()
.setFooter(client.user.username, client.user.displayAvatarURL({
dynamic: true
}));
return message.channel.send(embed);
} else {
client.guilds.cache.forEach((guild) => {
const getDefaultChannel = (guild) => {
if (guild.systemChannel) return guild.systemChannel;
return guild.channels.cache.filter(c => c.type == `text` && c.permissionsFor(guild.client.user).has(`SEND_MESSAGES`)).sort((a, b) => a.position - b.position || Long.fromString(a.id).sub(Long.fromString(b.id)).toNumber()).first();
};
const embed = new Discord.MessageEmbed()
.setColor(`#0099FF`)
.setAuthor(message.author.username, message.author.displayAvatarURL({
dynamic: true
}))
.setDescription(args[0])
.setTimestamp()
.setFooter(client.user.username, client.user.displayAvatarURL({
dynamic: true
}));
return getDefaultChannel(guild).send(embed);
});
};
};
});
client.login(token);