2022-03-30 01:45:11 +02:00
|
|
|
const Discord = require('discord.js');
|
|
|
|
const config = require('./config.json');
|
|
|
|
const {SlashCommandBuilder} = require("@discordjs/builders")
|
|
|
|
const friendsCommands = require('./friendsCommands.json')
|
2022-03-30 08:34:27 +02:00
|
|
|
const {GuildEmoji, Emoji, CommandInteraction} = require("discord.js");
|
2022-03-30 01:45:11 +02:00
|
|
|
const Client = new Discord.Client({
|
|
|
|
intents: [
|
|
|
|
Discord.Intents.FLAGS.GUILDS,
|
|
|
|
Discord.Intents.FLAGS.GUILD_MESSAGES,
|
2022-03-30 08:34:27 +02:00
|
|
|
Discord.Intents.FLAGS.GUILD_MESSAGE_REACTIONS,
|
|
|
|
Discord.Intents.FLAGS.GUILD_MEMBERS
|
2022-03-30 01:45:11 +02:00
|
|
|
]
|
|
|
|
});
|
|
|
|
const data = new SlashCommandBuilder()
|
2022-03-30 08:34:27 +02:00
|
|
|
.setName("react")
|
|
|
|
.setDescription("Créer un ajout de rôle")
|
|
|
|
.addStringOption(option =>
|
|
|
|
option.setName('role')
|
|
|
|
.setDescription('Le rôle à ajouter')
|
|
|
|
.setRequired(true)
|
|
|
|
.addChoice('Lol', 'League_of_Legends')
|
|
|
|
.addChoice('OW', 'OverWatch')
|
|
|
|
.addChoice('SW', 'Summoners_War')
|
|
|
|
)
|
2022-03-30 01:45:11 +02:00
|
|
|
|
|
|
|
|
|
|
|
let embedCommands = new Discord.MessageEmbed().setTitle("Liste des commandes").setColor("#ff0505")
|
|
|
|
.setDescription("Voici mes commandes - (N'oublier pas le '!' )")
|
|
|
|
.setThumbnail("https://www.artmajeur.com/medias/standard/k/o/koldin-84/artwork/9533635_alone-anime-anime-art-anime-boy-favim-com-1898320.jpg")
|
|
|
|
.setTimestamp()
|
|
|
|
.setFooter("Si vous souhaitez rajouter une commande, n'hésitez pas à contacter mon créateur")
|
|
|
|
|
|
|
|
Client.on("ready", async () => {
|
|
|
|
fromCommandsToEmbed(friendsCommands.commands)
|
2022-03-30 08:34:27 +02:00
|
|
|
console.log(`Logged in as ${Client.user.tag}!`)
|
2022-03-30 01:45:11 +02:00
|
|
|
// pour tout les serveurs - lent : Client.application.commands.create(data)
|
2022-03-30 08:34:27 +02:00
|
|
|
/*await Client.guilds.cache.get("903598468306702336").commands.create(data)
|
2022-03-30 01:45:11 +02:00
|
|
|
.then(() => {
|
|
|
|
console.log(`Logged in as ${Client.user.tag}!`)
|
|
|
|
|
|
|
|
})
|
|
|
|
.catch(r => {
|
|
|
|
console.log("Erreur lors de l'ajout de la commande\n" + r)
|
|
|
|
Client.destroy()
|
2022-03-30 08:34:27 +02:00
|
|
|
})*/
|
2022-03-30 01:45:11 +02:00
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
Client.login(config.token)
|
2022-03-30 08:34:27 +02:00
|
|
|
/* config prod
|
|
|
|
* {
|
|
|
|
"clientId": "890975056400904242",
|
|
|
|
"guildId": "876543210987654321",
|
|
|
|
"token": "ODkwOTc1MDU2NDAwOTA0MjQy.YU3nLg.T5wCbJ4UuDBanMjVaE-JX-aSELo",
|
|
|
|
"authorId": "307975903999164416"
|
|
|
|
}
|
|
|
|
* */
|
2022-03-30 01:45:11 +02:00
|
|
|
// dev token OTA1NDMzMzQ5MDgwODc1MDM4.YYKAhA.lX9_YqbkTxlkSfnYPOKa2pl5V8s && "clientId": "905433349080875038",
|
|
|
|
Client.on("interactionCreate", async interaction => {
|
|
|
|
if (interaction.isCommand()) {
|
2022-03-30 08:34:27 +02:00
|
|
|
const {commandName} = interaction
|
|
|
|
|
|
|
|
if (commandName === "games") {
|
2022-03-30 01:45:11 +02:00
|
|
|
let embed = new Discord.MessageEmbed()
|
|
|
|
.setTitle("Mini-Jeux")
|
|
|
|
.setColor("#ff0505")
|
|
|
|
.setDescription("Voici mes mini-jeux en ligne")
|
|
|
|
.setThumbnail("https://www.artmajeur.com/medias/standard/k/o/koldin-84/artwork/9533635_alone-anime-anime-art-anime-boy-favim-com-1898320.jpg")
|
|
|
|
.addField("__SUTOM__", "https://sutom.nocle.fr/")
|
|
|
|
.addField("__WORlDLE__", "https://worldle.teuteuf.fr/")
|
|
|
|
.addField("__LETTERS__", "https://edjefferson.com/letterle/ ")
|
|
|
|
.setTimestamp()
|
|
|
|
await interaction.channel.send({embeds: [embed]})
|
2022-03-30 08:34:27 +02:00
|
|
|
interaction.reply({content: 'Done ! :white_check_mark:', ephemeral: true,})
|
|
|
|
|
|
|
|
} else if (commandName === "help") {
|
2022-03-30 01:45:11 +02:00
|
|
|
await interaction.channel.send({embeds: [embedCommands]})
|
2022-03-30 08:34:27 +02:00
|
|
|
interaction.reply({content: 'Done ! :white_check_mark:', ephemeral: true,})
|
|
|
|
|
|
|
|
} else if (commandName === 'react') {
|
|
|
|
const message = await interaction.reply({content: 'Ajout du role : ' + interaction.options._hoistedOptions[0].value, fetchReply: true});
|
|
|
|
console.log( interaction.options)
|
|
|
|
|
|
|
|
message.react('👍')
|
|
|
|
.then(() => message.react('👎'))
|
|
|
|
.catch(error => console.error('One of the emojis failed to react:', error))
|
|
|
|
|
|
|
|
const filter = (reaction, user) => {
|
|
|
|
return ['👍', '👎'].includes(reaction.emoji.name) && user.id === interaction.user.id;
|
|
|
|
};
|
|
|
|
message.awaitReactions({filter, max: 1, time: 60000, errors: ['time']})
|
|
|
|
.then(collected => {
|
|
|
|
const reaction = collected.first();
|
|
|
|
if (reaction.emoji.name === '👍') {
|
|
|
|
message.reply('Ajout effectué !');
|
|
|
|
} else {
|
|
|
|
message.reply('Suppression effectuée !');
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.catch(collected => {
|
|
|
|
message.reply('You reacted with neither a thumbs up, nor a thumbs down.');
|
|
|
|
});
|
2022-03-30 01:45:11 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
Client.on('messageCreate', message => {
|
|
|
|
/*
|
|
|
|
console.log(`Message [${message.content}] sent from : ${message.author.username}#${message.author.tag}`)
|
|
|
|
*/
|
|
|
|
if (message.author.bot) {
|
|
|
|
} else if (message.content === "55857548596523514251458-)Nydalicor" && message.author.id === config.authorId) {
|
|
|
|
Client.destroy()
|
|
|
|
console.log("Bye Bye")
|
|
|
|
} else if (message.content === "update-)Nydalicor") {
|
|
|
|
Client.destroy()
|
|
|
|
console.log("Reloading... ")
|
|
|
|
Client.login(config.token)
|
|
|
|
console.log("Successfully reloaded")
|
|
|
|
} else if (message.content.indexOf("!") === 0) {
|
|
|
|
let commands = friendsCommands.commands
|
|
|
|
commands.forEach(command => {
|
|
|
|
if (message.content.substring(1, message.content.length) === command.key)
|
|
|
|
send(message, command.value)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
})
|
2022-03-30 08:34:27 +02:00
|
|
|
Client.on('messageReactionAdd', async (reaction, user) => {
|
|
|
|
// When a reaction is received, check if the structure is partial
|
|
|
|
if (reaction.partial) {
|
|
|
|
// If the message this reaction belongs to was removed, the fetching might result in an API error which should be handled
|
|
|
|
try {
|
|
|
|
await reaction.fetch();
|
|
|
|
if (reaction.emoji.name === '👍') {
|
|
|
|
|
|
|
|
reaction.reply("J'ajoute ton rôle")
|
|
|
|
}
|
|
|
|
} catch
|
|
|
|
(error) {
|
|
|
|
console.error('Something went wrong when fetching the message:', error);
|
|
|
|
// Return as `reaction.message.author` may be undefined/null
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
2022-03-30 01:45:11 +02:00
|
|
|
|
|
|
|
|
|
|
|
function fromCommandsToEmbed(commands) {
|
|
|
|
commands.forEach(command => {
|
|
|
|
addCommandToEmbed(command.key, embedCommands)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
function addCommandToEmbed(title, embed) {
|
|
|
|
embed.addField(title, "-")
|
|
|
|
}
|
|
|
|
|
|
|
|
function send(message, str) {
|
|
|
|
message.channel.send(str);
|
|
|
|
}
|
|
|
|
|