This commit is contained in:
Lukian LEIZOUR 2023-03-30 16:24:53 +02:00
parent 4d944dd64a
commit 7cbaa32b60
3 changed files with 64 additions and 22 deletions

7
app.js
View file

@ -219,14 +219,13 @@ bot.command('addmsg', async ctx => {
}) })
//Discord events //Discord events
client.on('ready', () => { discordEvents.ready(client);
console.log(`[Discord] Logged in as ${client.user.tag} !`);
client.user.setPresence({ activities: [{ name: 'la belle chaise', type : 3}] });
});
discordEvents.newMessage(client); discordEvents.newMessage(client);
discordEvents.newInteraction(client); discordEvents.newInteraction(client);
discordEvents.guildCreate(client);
bot.launch() bot.launch()
client.login(process.env.DISCORD); client.login(process.env.DISCORD);

View file

@ -1,4 +1,4 @@
const {REST , Routes, ApplicationCommandOptionType} = require('discord.js'); const {ApplicationCommandOptionType} = require('discord.js');
const commands = [ const commands = [
{ {
@ -102,21 +102,11 @@ const commands = [
name : 'github', name : 'github',
description : 'Get the github link of the bot', description : 'Get the github link of the bot',
}, },
{
name : 'servers',
description : 'Get the number of servers the bot is in',
},
]; ];
const rest = new REST({ version: '10' }).setToken(process.env.DISCORD); module.exports = { commands };
(async () => {
try {
console.log('Started refreshing application (/) commands.');
await rest.put(
Routes.applicationGuildCommands('<your discord bot ID>', '<your discord server ID>'),
{ body: commands },
);
console.log('Successfully reloaded application (/) commands.');
} catch (error) {
console.error(error);
}
})();

View file

@ -4,6 +4,8 @@ const { addToLogs } = require('../libs/botTools');
const { generateImage, answerQuestion, sendConv } = require('../libs/openAi'); const { generateImage, answerQuestion, sendConv } = require('../libs/openAi');
const { incrementQuota, addConv, delConv, getConvs, addMessage, getMessages, isNewUser } = require('../libs/mysql'); const { incrementQuota, addConv, delConv, getConvs, addMessage, getMessages, isNewUser } = require('../libs/mysql');
const { commands } = require('../commands/commands');
async function gptrequest(interaction) { async function gptrequest(interaction) {
await interaction.deferReply(); await interaction.deferReply();
@ -323,6 +325,14 @@ async function github(interation) {
console.log('[Discord] Github requested by ' + interaction.member.user.username); console.log('[Discord] Github requested by ' + interaction.member.user.username);
} }
async function servers(client) {
console.log("Serveurs:");
client.guilds.cache.forEach((guild) => {
console.log(" - " + guild);
})
}
module.exports = { module.exports = {
newMessage: (client) => { newMessage: (client) => {
client.on('messageCreate', async msg => { client.on('messageCreate', async msg => {
@ -384,6 +394,49 @@ module.exports = {
else if (interaction.commandName === 'github') { else if (interaction.commandName === 'github') {
github(interaction); github(interaction);
} }
else if (interaction.commandName === 'servers') {
servers(client);
}
}); });
} },
ready: (client) => {
client.on('ready', () => {
console.log(`[Discord] Logged in as ${client.user.tag} !`);
client.user.setPresence({ activities: [{ name: 'la belle chaise', type: 3 }] });
const rest = new discord.REST({ version: '10' }).setToken(process.env.DISCORD);
client.guilds.cache.forEach(async (guild) => {
try {
await rest.put(
discord.Routes.applicationGuildCommands('1059559067846189067', guild.id),
{ body: commands },
);
console.log('[Discord] Successfully reloaded application (/) commands for ' + guild.name + '.');
} catch (error) {
console.error(error);
}
})
});
},
guildCreate: (client) => {
client.on('guildCreate', async (guild) => {
const rest = new discord.REST({ version: '10' }).setToken(process.env.DISCORD);
try {
await rest.put(
discord.Routes.applicationGuildCommands('1059559067846189067', guild.id),
{ body: commands },
);
console.log('[Discord] Successfully reloaded application (/) commands for ' + guild.name + '.');
} catch (error) {
console.error(error);
}
});
},
} }