Advertisement
Victor10782

Index.js Discord.js V14

Feb 8th, 2024 (edited)
1,364
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JavaScript 2.23 KB | Source Code | 0 0
  1. /*Minha index.js, altere como desejar, pegue referências no Código e etc...
  2. Requisitos: Crie uma pasta chamada "source" e uma Subpasta chamada "cmd"
  3. Packages: discord.js ( Versão 14.11.0 )
  4. quick.db ( Versão 1.6.7 )
  5. better-sqlite3 ( Versão 8.2.0 )*/
  6.  
  7. const { InteractionType, Client, Collection, GatewayIntentBits } = require("discord.js");
  8. const client = new Client({ intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMembers, GatewayIntentBits.GuildMessages, GatewayIntentBits.MessageContent] });
  9. client.login("TOKEN DO BOT");
  10.  
  11. const { QuickDB } = require("quick.db");
  12. const db = new QuickDB();
  13. module.exports = db;
  14.  
  15. const fs = require("node:fs");
  16. const path = require("node:path");
  17. const PastaCmd = path.join(__dirname, "./source/cmd");
  18. const Arquivos = fs.readdirSync(PastaCmd).filter(f => f.endsWith(".js"));
  19. client.slashCommands = new Collection();
  20. const arr = [];
  21.  
  22. for (const f of Arquivos) {
  23.   const ArquivoDaPasta = path.join(PastaCmd, f);
  24.   const Arquivo = require(ArquivoDaPasta);
  25.   client.slashCommands.set(Arquivo.name, Arquivo);
  26.   arr.push(Arquivo);
  27. }
  28.  
  29. client.on("ready", () => {
  30.   client.application.commands.set(arr);
  31.   console.log(`[Client] ~ Login feito com Sucesso em "${client.user.tag}".\n[FilesLoader] ~ Carregado com Sucesso ${Arquivos.length} Arquivo(s).\n[DataBase] ~ Banco de Dados Pronto!`);
  32. });
  33.  
  34. client.on("interactionCreate", async interaction => {
  35.   if (interaction.user.bot) return;
  36.   if (!interaction.guild) {
  37.     return await interaction.reply({ content: `Me desculpe ${interaction.user.username} ! Mas você só pode executar meus comandos em um Servidor.`, ephemeral: true })
  38. }
  39.   if (interaction.type === InteractionType.ApplicationCommand) {
  40.     const cmd = await client.slashCommands.get(interaction.commandName);
  41.       if (!cmd) return await interaction.reply(`Algum erro inesperado ocorreu enquanto o Comando ${interaction.commandName} estava sendo Executado! Tente novamente.`);
  42.  
  43.     await cmd.run(client, interaction);
  44.   }
  45. });
  46.  
  47. client.on("messageCreate", async msg => {
  48.   if (msg.author.bot) return;
  49.   if (msg.content == `<@${client.user.id}>` || msg.content == `<@!${client.user.id}>`) {
  50.     await msg.reply("Olá **${msg.author.username}** !");
  51.   }
  52. });
  53.  
  54. module.exports = client;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement