├── .gitignore ├── commands ├── ping.js ├── playlist.js ├── docs.js └── git.js ├── package.json ├── deploy-commands.js └── index.js /.gitignore: -------------------------------------------------------------------------------- 1 | /node_modules 2 | .env -------------------------------------------------------------------------------- /commands/ping.js: -------------------------------------------------------------------------------- 1 | const { SlashCommandBuilder } = require("discord.js") 2 | 3 | module.exports = { 4 | data: new SlashCommandBuilder() 5 | .setName("ping") 6 | .setDescription("Responde com 'Pong!"), 7 | 8 | async execute(interaction) { 9 | await interaction.reply("Pong!") 10 | } 11 | } -------------------------------------------------------------------------------- /commands/playlist.js: -------------------------------------------------------------------------------- 1 | const { SlashCommandBuilder } = require("discord.js") 2 | 3 | module.exports = { 4 | data: new SlashCommandBuilder() 5 | .setName("playlist") 6 | .setDescription("Ouça a melhor playlist de estudos"), 7 | 8 | async execute(interaction) { 9 | await interaction.reply("https://open.spotify.com/playlist/5TUxgTIxzLbLVh7RUf9V8i?si=d79ad3b1a72840b6") 10 | } 11 | } -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "dependencies": { 3 | "discord.js": "^14.8.0", 4 | "dotenv": "^16.0.3" 5 | }, 6 | "name": "bot-discord", 7 | "version": "1.0.0", 8 | "main": "index.js", 9 | "scripts": { 10 | "test": "echo \"Error: no test specified\" && exit 1" 11 | }, 12 | "keywords": [ 13 | "bot-discord" 14 | ], 15 | "author": "Cristiano Rasweiler Neto", 16 | "license": "ISC", 17 | "description": "bot de estudos de programacao para discord" 18 | } 19 | -------------------------------------------------------------------------------- /deploy-commands.js: -------------------------------------------------------------------------------- 1 | const { REST, Routes } = require("discord.js") 2 | 3 | // dotenv 4 | const dotenv = require('dotenv') 5 | dotenv.config() 6 | const { TOKEN, CLIENT_ID, GUILD_ID } = process.env 7 | 8 | // importação dos comandos 9 | const fs = require("node:fs") 10 | const path = require("node:path") 11 | const commandsPath = path.join(__dirname, "commands") 12 | const commandFiles = fs.readdirSync(commandsPath).filter(file => file.endsWith(".js")) 13 | 14 | const commands = [] 15 | 16 | for (const file of commandFiles) { 17 | const command = require(`./commands/${file}`) 18 | commands.push(command.data.toJSON()) 19 | } 20 | 21 | // instância REST 22 | const rest = new REST({version: "10"}).setToken(TOKEN); 23 | 24 | // deploy 25 | (async () => { 26 | try { 27 | console.log(`Resentando ${commands.length} comandos...`) 28 | 29 | // PUT 30 | const data = await rest.put( 31 | Routes.applicationGuildCommands(CLIENT_ID, GUILD_ID), 32 | {body: commands} 33 | ) 34 | console.log("Comandos registrados com sucesso!") 35 | } 36 | catch (error){ 37 | console.error(error) 38 | } 39 | })() -------------------------------------------------------------------------------- /commands/docs.js: -------------------------------------------------------------------------------- 1 | const { SlashCommandBuilder, ActionRowBuilder, StringSelectMenuBuilder, Component } = require("discord.js") 2 | 3 | const row = new ActionRowBuilder() 4 | .addComponents( 5 | new StringSelectMenuBuilder() 6 | .setCustomId("select") 7 | .setPlaceholder("Nenhuma linguagem selecionada") 8 | .addOptions({ 9 | label: "javascript", 10 | description: "Veja a documentação de Javascript", 11 | value: "javascript" 12 | }, 13 | { 14 | label: "python", 15 | description: "Veja a documentação de Python", 16 | value: "python" 17 | }, 18 | { 19 | label: "C#", 20 | description: "Veja a documentação de C#", 21 | value: "csharp" 22 | }, 23 | { 24 | label: "discord.js", 25 | description: "Veja a documentação de Discord.js", 26 | value: "discordjs" 27 | } 28 | ) 29 | ) 30 | 31 | module.exports = { 32 | data: new SlashCommandBuilder() 33 | .setName("docs") 34 | .setDescription("Acesse a documentação da tecnologia que quiser"), 35 | 36 | async execute(interaction) { 37 | await interaction.reply({ content: "Selecione uma das techs abaixo:", components: [row] }) 38 | } 39 | } -------------------------------------------------------------------------------- /commands/git.js: -------------------------------------------------------------------------------- 1 | 2 | 3 | const { SlashCommandBuilder, EmbedBuilder } = require("discord.js") 4 | 5 | const exampleEmbed = new EmbedBuilder() 6 | .setColor("Orange") 7 | .setTitle("Comandos do Git") 8 | .addFields( 9 | { name: '\u200B', value: '\u200B' }, 10 | { name: '$ git init [nome-do-projeto]', value: 'Cria um novo repositório local com um nome especificado', inline: true }, 11 | { name: '$ git clone [url]', value: 'Baixa um projeto e seu histórico de versão inteiro', inline: true }, 12 | { name: '$ git stash', value: 'Armazena temporariamente todos os arquivos monitorados modificados', inline: true }, 13 | { name: '\u200B', value: '\u200B' }, 14 | { name: '$ git status', value: 'Revise edições e crie uma transação de commit', inline: true }, 15 | { name: '$ git add [arquivo]', value: 'Faz o snapshot de um arquivo na preparação para versionamento', inline: true }, 16 | { name: '$ git commit -m "[mensagem]"', value: 'Grava o snapshot permanentemente do arquivo no histórico de versão', inline: true }, 17 | { name: '\u200B', value: '\u200B' }, 18 | { name: '$ git branch', value: 'Lista todos os branches locais no repositório atual', inline: true }, 19 | { name: '$ git branch [nome-branch]', value: 'Cria uma nova branch', inline: true }, 20 | { name: '$ git switch -c [nome-branch]', value: 'Muda para a branch especificada e atualiza o diretório de trabalho', inline: true }, 21 | { name: '\u200B', value: '\u200B' }, 22 | { name: '$ git merge [nome-branch]', value: 'Combina o histórico da branch especificada a branch atual', inline: true }, 23 | { name: '$ git push [alias] [branch]', value: 'Envia todos os commits do branch local para o GitHub', inline: true }, 24 | { name: '$ git pull', value: 'Baixa o histórico e incorpora as mudanças', inline: true }, 25 | ) 26 | 27 | module.exports = { 28 | data: new SlashCommandBuilder() 29 | .setName("git") 30 | .setDescription("Relembrar comandos do Git"), 31 | 32 | async execute(interaction) { 33 | await interaction.reply({ embeds: [exampleEmbed] }) 34 | } 35 | } -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | const { Client, Events, GatewayIntentBits, Collection } = require('discord.js'); 2 | 3 | //dotenv 4 | const dotenv = require('dotenv') 5 | dotenv.config() 6 | const { TOKEN } = process.env 7 | 8 | // importação dos comandos 9 | const fs = require("node:fs") 10 | const path = require("node:path") 11 | const commandsPath = path.join(__dirname, "commands") 12 | const commandFiles = fs.readdirSync(commandsPath).filter(file => file.endsWith(".js")) 13 | 14 | const client = new Client({ intents: [GatewayIntentBits.Guilds] }) 15 | client.commands = new Collection 16 | 17 | for (const file of commandFiles) { 18 | const filePath = path.join(commandsPath, file) 19 | const command = require(filePath) 20 | if ("data" in command && "execute" in command) { 21 | client.commands.set(command.data.name, command) 22 | } else { 23 | console.log(`Esse comando em ${filePath} está com "data" ou "execute ausentes"`) 24 | } 25 | } 26 | 27 | // Login do bot 28 | client.once(Events.ClientReady, c => { 29 | console.log(`Pronto! Login realizado como ${c.user.tag}`) 30 | }); 31 | client.login(TOKEN) 32 | 33 | // Listener de interações com o bot 34 | client.on(Events.InteractionCreate, async interaction => { 35 | if (interaction.isStringSelectMenu()) { 36 | const selected = interaction.values[0] 37 | if (selected == "javascript") { 38 | await interaction.reply("Documentação do Javascript: https://developer.mozilla.org/en-US/docs/Web/JavaScript") 39 | } else if (selected == "python") { 40 | await interaction.reply("Documentação do Python: https://www.python.org") 41 | } else if (selected == "csharp") { 42 | await interaction.reply("Documentação do C#: https://learn.microsoft.com/en-us/dotnet/csharp/") 43 | } else if (selected == "discordjs") { 44 | await interaction.reply("Documentação do Discord.js: https://discordjs.guide/#before-you-begin") 45 | } 46 | } 47 | if (!interaction.isChatInputCommand()) return 48 | const command = interaction.client.commands.get(interaction.commandName) 49 | if (!command) { 50 | console.error("Comando não encontrado") 51 | return 52 | } 53 | try { 54 | await command.execute(interaction) 55 | } catch (error) { 56 | console.error(error); 57 | await interaction.reply("Houve um erro ao executar este comando!") 58 | } 59 | }) --------------------------------------------------------------------------------