Discord bot yazdığım komuta cevap vermiyor

Pysi Developer

Decapat
Katılım
9 Ekim 2021
Mesajlar
549
Yer
Kocaeli/Gebze
Arkadaşlar, Discord bot yazmaya karar verdim. İzlediğim bir videodan şu kodu yazdım zaten klasik kod sanırım ama "sa" yazınca bot yanıt vermiyor. Neden olabilir?

const Discord = require('discord.js');
const client = new Discord.Client();
client.on('ready', () => {
console.log(`${client.user.tag} Aktif !`);
});

client.on('message', msg => {
if (msg.content === 'sa') {

msg.reply('as');
}
});
client.login('');
 
Arkadaşlar, Discord bot yazmaya karar verdim. İzlediğim bir videodan şu kodu yazdım zaten klasik kod sanırım ama "sa" yazınca bot yanıt vermiyor. Neden olabilir?

const Discord = require('discord.js');
const client = new Discord.Client();
client.on('ready', () => {
console.log(`${client.user.tag} Aktif !`);
});

client.on('message', msg => {
if (msg.content === 'sa') {

msg.reply('as');
}
});
client.login('');
Hangi sürümü kullanıyorsunuz?
 
Hocam bu kod sadece eski sürüm Discord.js kütüphanesinde çalışır. Yeni versiyonlarda çalışmaz. Üstüne üstlük artık message(değişti messageCreate oldu) eventini dinleyebilmek için message content intent adında bir şeyi developer portaldan açmış olmanız ve bunun client'i tanımlarken intents: olarak tanımlanamanız gerekiyor.

Kısacası kod zaten eski, bu kod çalışmaz. Çalışsa bile dediğim gibi intents falan işin içine giriyor, işiniz uzun.
discord.js Guide bu site işinize yarar, okuyun, anlayın.

Örnek:
JavaScript:
// Require the necessary discord.js classes
const { Client, Events, GatewayIntentBits } = require('discord.js');
const { token } = require('./config.json');

// Create a new client instance
const client = new Client({ intents: [GatewayIntentBits.Guilds] });

// When the client is ready, run this code (only once)
// We use 'c' for the event parameter to keep it separate from the already defined 'client'
client.once(Events.ClientReady, c => {
    console.log(`Ready! Logged in as ${c.user.tag}`);
});

// Log in to Discord with your client's token
client.login(token);
 
Hangi sürümü kullanıyorsunuz?
12.5.3 discord.js

Hocam bu kod sadece eski sürüm Discord.js kütüphanesinde çalışır. Yeni versiyonlarda çalışmaz. Üstüne üstlük artık message(değişti messageCreate oldu) eventini dinleyebilmek için message content intent adında bir şeyi developer portaldan açmış olmanız ve bunun client'i tanımlarken intents: olarak tanımlanamanız gerekiyor.

Kısacası kod zaten eski, bu kod çalışmaz. Çalışsa bile dediğim gibi intents falan işin içine giriyor, işiniz uzun.
discord.js Guide bu site işinize yarar, okuyun, anlayın.

Örnek:
JavaScript:
// Require the necessary discord.js classes
const { Client, Events, GatewayIntentBits } = require('discord.js');
const { token } = require('./config.json');

// Create a new client instance
const client = new Client({ intents: [GatewayIntentBits.Guilds] });

// When the client is ready, run this code (only once)
// We use 'c' for the event parameter to keep it separate from the already defined 'client'
client.once(Events.ClientReady, c => {
    console.log(`Ready! Logged in as ${c.user.tag}`);
});

// Log in to Discord with your client's token
client.login(token);
Anladım hocam bakayım ben.
 

Yeni konular

Geri
Yukarı