-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
64 lines (56 loc) · 2.28 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// classes para importar o discord.js
const { Client, Events, GatewayIntentBits, Collection } = require('discord.js');
// criando nova instancia client
const client = new Client({ intents: [GatewayIntentBits.Guilds] });
client.commands = new Collection();
// require dotenv
const dotenv = require('dotenv');
dotenv.config();
const {TOKEN, CLIENT_ID, GUILD_ID} = process.env;
//import slash command of file
const fs = require("node:fs");
const path = require("node:path");
const commandsPath = path.join(__dirname, "slash_commands")
const commandsFiles = fs.readdirSync(commandsPath).filter(file => file.endsWith(".js"))
for (const file of commandsFiles){
const filePath = path.join(commandsPath, file);
const command = require(filePath);
if("data" in command && "execute" in command){
client.commands.set(command.data.name, command)
}else{
console.log(`Pronto! Login realizado com ${filePath} esta com "data" ou "execute ausente"`)
}
}
// Log in to Discord with your client's token
client.once(Events.ClientReady, c => {
console.log(`Pronto! Login realizado com ${c.user.tag}`);
});
client.login(TOKEN);
//interação com o bot
client.on(Events.InteractionCreate, async interaction =>{
if (interaction.isStringSelectMenu()){
const selected = interaction.values[0]
if (selected == "javascript"){
await interaction.reply("Documentação do Javascript: https://developer.mozilla.org/en-US/docs/Web/JavaScript")
} else if (selected == "python"){
await interaction.reply("Documentação do Python: https://www.python.org")
} else if (selected == "csharp"){
await interaction.reply("Documentação do C#: https://learn.microsoft.com/en-us/dotnet/csharp/")
} else if (selected == "java"){
await interaction.reply("Documentação do Java: https://dev.java/learn/")
}
}
if(!interaction.isChatInputCommand())
return
const command = interaction.client.commands.get(interaction.commandName);
if(!command) {
console.console.error("Comando não encontrado!");
return
}
try{
await command.execute(interaction)
} catch(error){
console.error(error)
await interaction.reply("Houve um erro ao executar esse comando!")
}
});