Bonjour,
Je rencontre un petit problème avec mon bot discord lorsque je l'heberg sous linux
const Discord = require("discord.js");
const { MessageEmbed, Client, GuildChannel, MessageAttachment } = require('discord.js');
const bot = new Discord.Client();
bot.on('ready', () => {
console.log(`le bot ${bot.user.tag} est connecté avec succès! {^_^}`);
});
bot.on('message', (message) => {
if (message.content.includes('discord.gg'||'discordapp.com/invite/')) {
message.channel.send(new Discord.MessageEmbed()
.setTitle('**RAPPEL AU REGLEMENT :**')
.addField('**:balloon: Tu peux envoyer une pub toutes les**', "**deux heures dans ce salon!**")
.addField('**:balloon: Si vous quittez le serveur**', "**vos pubs seront supprimées**")
.addField('**:balloon: Les publicités NSFW en tout genre**', "**sont interdites.**")
.addField(`**:balloon: N'hésite pas à revoir le règlement**`, "**pour te rafraîchir la mémoire :smile: **")
.addField(':balloon: Bonne pub :tada: !', `${message.author.tag}`)
.setColor('YELLOW'))
} if (message.content.startsWith("tr!embed")) {
let args = message.content.split(' ');
args.shift()
if (!args[0]) return message.channel.send(new Discord.MessageEmbed()
.setTitle('Mauvaise utilisation :x:')
.setDescription('Essayez plutot tr!embed `message`')
.setFooter(`Embed crée par ${message.author.tag}`)
.setColor('RANDOM'))
let msg = args.join(' ');
message.channel.send(new Discord.MessageEmbed()
.setTitle(`${msg}`)
.setColor('RANDOM'))
} if (message.content.startsWith("tr!say")) {
let args = message.content.split(' ');
args.shift()
if (!args[0]) return message.channel.send(new Discord.MessageEmbed)
.setTitle('Mauvaise utilisation :x:')
.setDescription('Essayez plutot !say `message`')
let msg = args.join(' ');
message.channel.send(`${msg}`)
} if (message.content.startsWith("tr!sondage")) {
let args = message.content.split(' ');
args.shift()
if (!args[0]) return message.channel.send("**Précisez votre sondage. !sondage `question`**");
let msg = args.join(' ');
message.channel.send(new Discord.MessageEmbed()
.setTitle("**Sondage :**")
.setDescription(`**${msg}**`)
.setFooter(`Sondage proposé par ${message.author.tag}.`)
.setColor('RANDOM'))
.then(msg => msg.react('✅')
(msg.react('❌'))
)
}})
bot.on("ready", () => {
bot.user.setPresence({ activity: { name: `tr!help pour de l'aide `, status: 'WATCHING' } });
})
bot.on('guildMemberAdd', message => {
let member = message.guild.member.mentions
bot.channels.cache.get('754665289291137024').send(new Discord.MessageEmbed()
.setTitle('**Un nouveau membre ! :tada:**')
.setDescription(`**Bienvenue, ${member} !**`)
.setFooter(`Nous sommes désormais ${(bot.guilds.cache.get(message.guild.id).memberCount)}`)
.setColor('RANDOM'))
});
bot.on("message", message => {
if (message.content === "tr!help") {
let url = `https://discord.gg/vW57Gqa`
message.channel.send(new Discord.MessageEmbed()
.setTitle(`__*Voici mes fonctionnalités ⚡️*__`)
.addField('◼️ **MON PREFIX :**', 'tr')
.addField('◼️ **Modération :**', "`kick` / `ban` / `clear` / `userinfo`")
.addField("◼️ **Serveur :** ", " `mcount`")
.addField("◼️ **Utilité : **", "`embed` / `say` / `sondage`/`avatar`/ 8ball")
.setFooter(`Commande éxecutée par ${message.author.tag}`, message.author.displayAvatarURL())
.setColor('RANDOM')
)
}
})
bot.on("message", message => {
if (message.content.startsWith("tr!clear")) {
if (!message.member.hasPermission("MANAGE_MESSAGES")) return;
let args = message.content.split(' ');
args.shift();
if (!args[0]) return message.channel.send("**Veuillez spécifier le nombre de messages à supprimer.**");
let number = parseInt(args[0]);
if (isNaN(number)) return message.channel.send("**Veuillez entrer un nombre valide**");
message.channel.bulkDelete(number).then(message.channel.send(`**${number} messages ont bien été supprimés**`).then(msg => msg.delete({ timeout: 3000 })));
}
if (message.content.startsWith("tr!ban")) {
if (!message.member.hasPermission("BAN_MEMBERS")) return;
let member = message.mentions.members.first();
if (!member) return message.channel.send("**Veuillez mentionner quelqu'un à bannir.**");
member.ban().then(message.channel.send(`${member} a été banni par ${message.member}`));
}
if (message.content.startsWith("tr!userinfo")) {
let member = message.mentions.members.first() || message.member;
let roles = '';
let joinedat = `${member.joinedAt.getFullYear()}-${member.joinedAt.getMonth() + 1}-${member.joinedAt.getDate()} à ${member.joinedAt.getHours()}:${member.joinedAt.getMinutes()}`;
let createdat = `${member.user.createdAt.getFullYear()}-${member.user.createdAt.getMonth() + 1}-${member.user.createdAt.getDate()} à ${member.user.createdAt.getHours()}:${member.user.createdAt.getMinutes()}`;
member.roles.cache.each(r => roles += `<@&${r.id}> `);
message.channel.send(new Discord.MessageEmbed()
.addField("**A crée son compte le :**", createdat)
.addField("**A rejoint le serveur le :**", joinedat)
.addField("**Roles sur le serveur :**", roles)
.addField("**ID :**", member.id)
.setThumbnail(member.user.displayAvatarURL())
.setFooter(`Demandé par ${message.author.tag}`, message.author.displayAvatarURL())
)
}
bot.on("message", message => {
if (message.content === 'tr!mcount') {
message.channel.send(new Discord.MessageEmbed()
.setTitle(`**Nous sommes ${(bot.guilds.cache.get(message.guild.id).memberCount)} sur ce serveur.**`)
.setDescription(`:tada: **${(bot.guilds.cache.get(message.guild.id))}** :tada:`)
.setColor('RANDOM'))
}})})
bot.on('message', message => {
if (message.content === 'tr!ping') {
message.channel.send(`🏓 Pong ! Ma latence est de ${Math.round(bot.ws.ping)} ms.`);
}
});
bot.on('message', message => {
if (message.content === 'tr!staff') {
message.channel.send("pour conatcter le staff effectue la commande **!mail <ton-message>**");
}
});
bot.on('guildMemberAdd', member => {
bot.channels.cache.get('741299853065453568').send(new Discord.MessageEmbed()
.setTitle('**Un nouveau membre ! :tada:**')
.setDescription(`**Bienvenue, ${member} !**`)
.setFooter(`Nous sommes désormais ${(bot.guilds.cache.get(message.guild.id).memberCount)}`)
.setColor('RANDOM'))
});
//test
//tests-avatar
bot.on("message", message => {
if (message.content.startsWith("tr!avatar")) {
if(message.channel.type === 'dm') return;
let member = message.mentions.members.first() || message.member;
let roles = '';
let joinedat = `${member.joinedAt.getFullYear()}-${member.joinedAt.getMonth() + 1}-${member.joinedAt.getDate()} ${member.joinedAt.getHours()}:${member.joinedAt.getMinutes()}`;
let createdat = `${member.user.createdAt.getFullYear()}-${member.user.createdAt.getMonth() + 1}-${member.user.createdAt.getDate()} ${member.user.createdAt.getHours()}:${member.user.createdAt.getMinutes()}`;
member.roles.cache.each(r => roles += `<@&${r.id}> `);
message.channel.send(new Discord.MessageEmbed()
.setColor("RANDOM")
.setTitle("Voici l'avatar demandé !")
.setImage(member.user.displayAvatarURL())
.setFooter(`Par ${message.author.tag}`, message.author.displayAvatarURL())
)
}
})
//8ball
bot.on('message', message => {
if (message.content.startsWith("tr!8ball")) {
if(message.channel.type === 'dm') return;
let args = message.content.split(' ');
args.shift();
if (!args.join('').endsWith("?")) return message.channel.send('Précisez votre question ! FInissez aussi votre question par un **?**')
let msg = args.join(' ');
let possibilites = ['Oui !', 'Non !', 'Je ne sais pas..'];
let r = Math.floor(Math.random() * ((possibilites.length - 1) - 0 + 1)) + 0;
let reponse = possibilites[r];
message.channel.send(new Discord.MessageEmbed()
.setTitle("8ball :8ball:")
.addField(`Question: **${msg}**`, `Réponse: **${possibilites[r]}**`)
.setFooter(`${message.author.tag}`)
.setColor('RANDOM')
)
}})
TypeError: fields.flat is not a function
at Function.normalizeFields (/home/pi/Desktop/bot/node_modules/discord.js/sr c/structures/MessageEmbed.js:450:8)
at MessageEmbed.addFields (/home/pi/Desktop/bot/node_modules/discord.js/src/ structures/MessageEmbed.js:266:42)
at MessageEmbed.addField (/home/pi/Desktop/bot/node_modules/discord.js/src/s tructures/MessageEmbed.js:257:17)
at Client.bot.on.message (/home/pi/Desktop/bot/index.js:84:14)
at Client.emit (events.js:203:15)
at MessageCreateAction.handle (/home/pi/Desktop/bot/node_modules/discord.js/ src/client/actions/MessageCreate.js:31:14)
at Object.module.exports [as MESSAGE_CREATE] (/home/pi/Desktop/bot/node_modu les/discord.js/src/client/websocket/handlers/MESSAGE_CREATE.js:4:32)
at WebSocketManager.handlePacket (/home/pi/Desktop/bot/node_modules/discord. js/src/client/websocket/WebSocketManager.js:384:31)
at WebSocketShard.onPacket (/home/pi/Desktop/bot/node_modules/discord.js/src /client/websocket/WebSocketShard.js:444:22)
at WebSocketShard.onMessage (/home/pi/Desktop/bot/node_modules/discord.js/sr c/client/websocket/WebSocketShard.js:301:10)