Türkçe Discord Bot

Discord.js kütüphanesini kullanan ve içinde bir komut işleyici bulunan bir bot örneği hazırladım.

Buraya Tıklayarak Örneğe Ulaşabilirsiniz.

Bağlantılar:

Discord

İmza: ! . 02 . !#9502

Etiketler:
Türkçe
Discord
Bot

Hey @discord-chan,
I’d like to point out few things, such as

  • There is no such method lenght.
  • Instead of popping the .js from the file name, you can just split the letters after ., let commandName = file.split(".")[0];
  • Etc…
const Discord = require("discord.js");
const client = new Discord.Client(); // Alıcı client olarak ayarlıdır! Buna dikkat edin!
const fs = require("fs");
const http = require("http");
const express = require("express");
const app = express();
const prefix = process.env.PREFIX;
client.commands = new Discord.Collection();

client.on("ready", () => {
console.log("Bağlantı Başarılı!");
});

fs.readdir('./komutlar/', (err, files) => {
if (err) console.error(err);
files.forEach((file) => {
if (!file.endsWith(".js")) return;
let props = require(`./commands/${file}`);
let commandName = file.split(".")[0];
console.log(`Attempting to load command ${commandName}`);
client.commands.set(commandName, props);
});
});


client.on('message', message => {
const messageArray = message.content.split(/\s+/g); // Mesaj, mesela "Merhaba Dostum!" mesajını ayrı nesnelere ayırır. Şöyle oluyor yani ["Merhaba","Dostum!"]
const command = messageArray[0]; // Ön-ek(prefix) ile komut.
const args = messageArray.slice(1); // Komuta verilen argümanlar.
let cmd = client.commands.get(command.slice(prefix.length)); // Koleksiyonunundan komut alıyor.

if(command.startsWith(prefix)){ // Komut nesnesi önekle başlıyorsa,
if(cmd) cmd.run(client, message, args); // cmd nesnesi boş değilse, komut kodunu çalıştır.
}
});

client.login(process.env.TOKEN);
1 Like