const { Client, GatewayIntentBits, Partials, REST, Routes, ActivityType, EmbedBuilder } = require('discord.js');
const { token, botID } = require('./config.json');
const client = new Client({ intents: 7796});
const commands = [
{
name: 'test',
description: 'test'
},
{
name: 'test2',
description: 'test2'
},
];
const rest = new REST({version: '10'}).setToken(token);
(async () => {
try {
await rest.put(Routes.applicationCommands(botID), { body: commands })
console.log('Komutlar Yüklendi ✅');
} catch (error){
console.log(error);
}
})();
client.on('interactionCreate', async (interaction) => {
if (!interaction.isChatInputCommand()) return;
if (interaction.commandName === 'test'){
await interaction.reply({ content: 'test.', ephemeral: false})
};
if (interaction.commandName === 'test2'){
await interaction.reply({ content: 'test2', ephemeral: false})
};
});
client.login(token).then(() => {
console.log('${client.user.username} ismi ile giriş yaptım! 🤖');
client.user.setStatus('idle');
client.user.setActivity({ name: '/yardım', type: ActivityType.Watching});
}).catch((err) => console.log(err));
Ben oraya ? operatörünü boşuna eklemedim. Sunucu offline olduğu için undefined dönüyordu. Gecikme bilgisi gelmiyor API'dan bu arada.@kaan.w
ping için aynı kodu yazıp sonuna ping ekledim fakat undefined diye çıkıyor sebebi nedir? bunun gibi:
JavaScript:if (interaction.commandName === 'sunucu'){ const res = await fetch('https://api.mcsrvstat.us/3/n1.1984.lol:6710'); const data = await res.json(); const { user } = interaction; const SunucuBilgi = new EmbedBuilder() .setTitle('Sunucu Bilgileri') .setDescription(`**<:oyuncu:1183833674316271817> Sunucudaki Aktif Oyuncu Sayısı:** ${data.players.online} oyuncu aktif!\n**<:ping:1183837072621064322> Sunucudaki Anlık Ping:** ${data.ping}ms`) .setColor('#0099ff') .setFooter({ text: `${user.username} Tarafından İstendi`, iconURL: user.displayAvatarURL() }) await interaction.deferReply(); await interaction.editReply({ embeds: [SunucuBilgi], ephemeral: false})
if (interaction.commandName === 'sunucu'){
const res = await fetch('https://api.mcsrvstat.us/3/n1.1984.lol:6710');
const data = await res.json();
const { user } = interaction;
const SunucuBilgi = new EmbedBuilder()
.setTitle('Sunucu Bilgileri')
.setDescription(data.online ? `**<:oyuncu:1183833674316271817> Sunucudaki Aktif Oyuncu Sayısı:** ${data.players.online} oyuncu aktif!` : "Sunucu aktif değil.")
.setColor('#0099ff')
.setFooter({ text: `${user.username} Tarafından İstendi`, iconURL: user.displayAvatarURL() })
await interaction.deferReply();
await interaction.editReply({ embeds: [SunucuBilgi], ephemeral: false})
async function getMinecraftServerData(adress) {
const res = await fetch(`https://api.mcsrvstat.us/3/${adress}`);
const data = await res.json();
return data;
}
const data = await getMinecraftServerData("hypixel.net");
console.log(`${data.players.online}/${data.players.max} players online.`);
//36996/200000 players online.
bunun için ekstra bir şey indirmem lazım mı yani tam olarak nasıl entegre edicem sunucunun adresini nereye yazcamBöyle bir fonksiyon yazdım, adresi parametre olarak verdiğinde sunucu bilgilerini geri döndürüyor. Nelere erişebileceğinize buradan bakabilirsiniz.
JavaScript:async function getMinecraftServerData(adress) { const res = await fetch(`https://api.mcsrvstat.us/3/${adress}`); const data = await res.json(); return data; }
Örnek olarak oyuncu sayısını bu şekilde alabiliriz. (async fonksiyon içinde çalıştırmalısınız.)
JavaScript:const data = await getMinecraftServerData("hypixel.net"); console.log(`${data.players.online}/${data.players.max} players online.`); //36996/200000 players online.
Bota entegre kısmını siz halledersiniz.
bunun için ekstra bir şey indirmem lazım mı yani tam olarak nasıl entegre edicem sunucunun adresini nereye yazcam
Hayır lazım değil.Bunun için ekstra bir şey indirmem lazım mı
fetch
bulunamadı gibi bir hata verirse npm install node-fetch
ile onu indirebilirsiniz.Gayet açık diye düşünüyorum nereye yazacağınız. Kabak gibi "hypixel.net" yazmışım oraya örnek olsun diye. Ayrıca botunuz da gördüğüm kadarıyla slash command ile çalışıyor prefixTam olarak nasıl entegre edicem sunucunun adresini nereye yazacağım
!
vs. yok yani. /aktiflik
ile çalıştıracaksınız.const { Client, GatewayIntentBits, Partials, REST, Routes, ActivityType, EmbedBuilder } = require('discord.js');
const { token, botID } = require('./config.json');
const client = new Client({ intents: 7796});
const commands = [
{
name: "aktiflik",
description: "sunucu aktifligi"
},
{
name: 'test',
description: 'test'
},
{
name: 'test2',
description: 'test2'
},
];
const rest = new REST({version: '10'}).setToken(token);
(async () => {
try {
await rest.put(Routes.applicationCommands(botID), { body: commands })
console.log('Komutlar Yüklendi ✅');
} catch (error){
console.log(error);
}
})();
client.on('interactionCreate', async (interaction) => {
if (!interaction.isChatInputCommand()) return;
if (interaction.commandName === 'aktiflik'){
const res = await fetch(`https://api.mcsrvstat.us/3/SUNUCUADRESI`);
const data = await res.json();
const content = `${data.players.online}/${data.players.max} oyuncu aktif.`
await interaction.reply({ content: content, ephemeral: false})
};
if (interaction.commandName === 'test'){
await interaction.reply({ content: 'test.', ephemeral: false})
};
if (interaction.commandName === 'test2'){
await interaction.reply({ content: 'test2', ephemeral: false})
};
});
client.login(token).then(() => {
console.log('${client.user.username} ismi ile giriş yaptım! 🤖');
client.user.setStatus('idle');
client.user.setActivity({ name: '/yardım', type: ActivityType.Watching});
}).catch((err) => console.log(err));
@kaan.wHayır lazım değil.fetch
bulunamadı gibi bir hata verirsenpm install node-fetch
ile onu indirebilirsiniz.
Gayet açık diye düşünüyorum nereye yazacağınız. Kabak gibi "hypixel.net" yazmışım oraya örnek olsun diye. Ayrıca botunuz da gördüğüm kadarıyla slash command ile çalışıyor prefix!
vs. yok yani./aktiflik
ile çalıştıracaksınız.
JavaScript:const { Client, GatewayIntentBits, Partials, REST, Routes, ActivityType, EmbedBuilder } = require('discord.js'); const { token, botID } = require('./config.json'); const client = new Client({ intents: 7796}); const commands = [ { name: "aktiflik", description: "sunucu aktifligi" }, { name: 'test', description: 'test' }, { name: 'test2', description: 'test2' }, ]; const rest = new REST({version: '10'}).setToken(token); (async () => { try { await rest.put(Routes.applicationCommands(botID), { body: commands }) console.log('Komutlar Yüklendi ✅'); } catch (error){ console.log(error); } })(); client.on('interactionCreate', async (interaction) => { if (!interaction.isChatInputCommand()) return; if (interaction.commandName === 'aktiflik'){ const res = await fetch(`https://api.mcsrvstat.us/3/SUNUCUADRESI`); const data = await res.json(); const content = `${data.players.online}/${data.players.max} oyuncu aktif.` await interaction.reply({ content: content, ephemeral: false}) }; if (interaction.commandName === 'test'){ await interaction.reply({ content: 'test.', ephemeral: false}) }; if (interaction.commandName === 'test2'){ await interaction.reply({ content: 'test2', ephemeral: false}) }; }); client.login(token).then(() => { console.log('${client.user.username} ismi ile giriş yaptım! 🤖'); client.user.setStatus('idle'); client.user.setActivity({ name: '/yardım', type: ActivityType.Watching}); }).catch((err) => console.log(err));
TypeError: Cannot read properties of undefined (reading 'online')
at Client.<anonymous> (C:\Users\Samsung\Desktop\Botlarım\Pulsar Network\index.js:73:41)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
Emitted 'error' event on Client instance at:
at emitUnhandledRejectionOrErr (node:events:397:10)
at process.processTicksAndRejections (node:internal/process/task_queues:84:21)
Sunucu offline olduğu için olmuş.@kaan.w
Kod:TypeError: Cannot read properties of undefined (reading 'online') at Client.<anonymous> (C:\Users\Samsung\Desktop\Botlarım\Pulsar Network\index.js:73:41) at process.processTicksAndRejections (node:internal/process/task_queues:95:5) Emitted 'error' event on Client instance at: at emitUnhandledRejectionOrErr (node:events:397:10) at process.processTicksAndRejections (node:internal/process/task_queues:84:21)
böyle bir hata aldım
const { Client, GatewayIntentBits, Partials, REST, Routes, ActivityType, EmbedBuilder } = require('discord.js');
const { token, botID } = require('./config.json');
const client = new Client({ intents: 7796});
const commands = [
{
name: "aktiflik",
description: "sunucu aktifligi"
},
{
name: 'test',
description: 'test'
},
{
name: 'test2',
description: 'test2'
},
];
const rest = new REST({version: '10'}).setToken(token);
(async () => {
try {
await rest.put(Routes.applicationCommands(botID), { body: commands })
console.log('Komutlar Yüklendi ✅');
} catch (error){
console.log(error);
}
})();
client.on('interactionCreate', async (interaction) => {
if (!interaction.isChatInputCommand()) return;
if (interaction.commandName === 'aktiflik'){
const res = await fetch(`https://api.mcsrvstat.us/3/SUNUCUADRESI`);
const data = await res.json();
const content = data.online ? `${data.players.online}/${data.players.max} oyuncu aktif.` : "Sunucu aktif değil."
await interaction.reply({ content: content, ephemeral: false})
};
if (interaction.commandName === 'test'){
await interaction.reply({ content: 'test.', ephemeral: false})
};
if (interaction.commandName === 'test2'){
await interaction.reply({ content: 'test2', ephemeral: false})
};
});
client.login(token).then(() => {
console.log('${client.user.username} ismi ile giriş yaptım! 🤖');
client.user.setStatus('idle');
client.user.setActivity({ name: '/yardım', type: ActivityType.Watching});
}).catch((err) => console.log(err));
@kaan.wSunucu offline olduğu için olmuş.
JavaScript:const { Client, GatewayIntentBits, Partials, REST, Routes, ActivityType, EmbedBuilder } = require('discord.js'); const { token, botID } = require('./config.json'); const client = new Client({ intents: 7796}); const commands = [ { name: "aktiflik", description: "sunucu aktifligi" }, { name: 'test', description: 'test' }, { name: 'test2', description: 'test2' }, ]; const rest = new REST({version: '10'}).setToken(token); (async () => { try { await rest.put(Routes.applicationCommands(botID), { body: commands }) console.log('Komutlar Yüklendi ✅'); } catch (error){ console.log(error); } })(); client.on('interactionCreate', async (interaction) => { if (!interaction.isChatInputCommand()) return; if (interaction.commandName === 'aktiflik'){ const res = await fetch(`https://api.mcsrvstat.us/3/SUNUCUADRESI`); const data = await res.json(); const content = data.online ? `${data.players.online}/${data.players.max} oyuncu aktif.` : "Sunucu aktif değil." await interaction.reply({ content: content, ephemeral: false}) }; if (interaction.commandName === 'test'){ await interaction.reply({ content: 'test.', ephemeral: false}) }; if (interaction.commandName === 'test2'){ await interaction.reply({ content: 'test2', ephemeral: false}) }; }); client.login(token).then(() => { console.log('${client.user.username} ismi ile giriş yaptım! 🤖'); client.user.setStatus('idle'); client.user.setActivity({ name: '/yardım', type: ActivityType.Watching}); }).catch((err) => console.log(err));
if (interaction.commandName === 'sunucu'){
const res = await fetch('https://api.mcsrvstat.us/3/n1.1984.lol:6710');
const data = await res.json();
const { user } = interaction;
const SunucuBilgi = new EmbedBuilder()
.setTitle('Sunucu Bilgileri')
.setDescription(`**<:oyuncu:1183833674316271817> Sunucudaki Aktif Oyuncu Sayısı:** ${data.players.online} oyuncu aktif!\n**<:ping:1183837072621064322> Sunucudaki Anlık Ping:** ${data.ping}ms`)
.setColor('#0099ff')
.setFooter({ text: `${user.username} Tarafından İstendi`, iconURL: user.displayAvatarURL() })
await interaction.deferReply();
await interaction.editReply({ embeds: [SunucuBilgi], ephemeral: false})
Ben oraya ? operatörünü boşuna eklemedim. Sunucu offline olduğu için undefined dönüyordu. Gecikme bilgisi gelmiyor API'dan bu arada.@kaan.w
ping için aynı kodu yazıp sonuna ping ekledim fakat undefined diye çıkıyor sebebi nedir? bunun gibi:
JavaScript:if (interaction.commandName === 'sunucu'){ const res = await fetch('https://api.mcsrvstat.us/3/n1.1984.lol:6710'); const data = await res.json(); const { user } = interaction; const SunucuBilgi = new EmbedBuilder() .setTitle('Sunucu Bilgileri') .setDescription(`**<:oyuncu:1183833674316271817> Sunucudaki Aktif Oyuncu Sayısı:** ${data.players.online} oyuncu aktif!\n**<:ping:1183837072621064322> Sunucudaki Anlık Ping:** ${data.ping}ms`) .setColor('#0099ff') .setFooter({ text: `${user.username} Tarafından İstendi`, iconURL: user.displayAvatarURL() }) await interaction.deferReply(); await interaction.editReply({ embeds: [SunucuBilgi], ephemeral: false})
if (interaction.commandName === 'sunucu'){
const res = await fetch('https://api.mcsrvstat.us/3/n1.1984.lol:6710');
const data = await res.json();
const { user } = interaction;
const SunucuBilgi = new EmbedBuilder()
.setTitle('Sunucu Bilgileri')
.setDescription(data.online ? `**<:oyuncu:1183833674316271817> Sunucudaki Aktif Oyuncu Sayısı:** ${data.players.online} oyuncu aktif!` : "Sunucu aktif değil.")
.setColor('#0099ff')
.setFooter({ text: `${user.username} Tarafından İstendi`, iconURL: user.displayAvatarURL() })
await interaction.deferReply();
await interaction.editReply({ embeds: [SunucuBilgi], ephemeral: false})
TeşekkürlerBen oraya ? operatörünü boşuna eklemedim. Sunucu offline olduğu için undefined dönüyordu. Gecikme bilgisi gelmiyor API'dan bu arada.
JavaScript:if (interaction.commandName === 'sunucu'){ const res = await fetch('https://api.mcsrvstat.us/3/n1.1984.lol:6710'); const data = await res.json(); const { user } = interaction; const SunucuBilgi = new EmbedBuilder() .setTitle('Sunucu Bilgileri') .setDescription(data.online ? `**<:oyuncu:1183833674316271817> Sunucudaki Aktif Oyuncu Sayısı:** ${data.players.online} oyuncu aktif!` : "Sunucu aktif değil.") .setColor('#0099ff') .setFooter({ text: `${user.username} Tarafından İstendi`, iconURL: user.displayAvatarURL() }) await interaction.deferReply(); await interaction.editReply({ embeds: [SunucuBilgi], ephemeral: false})
Ben oraya ? operatörünü boşuna eklemedim. Sunucu offline olduğu için undefined dönüyordu. Gecikme bilgisi gelmiyor API'dan bu arada.
JavaScript:if (interaction.commandName === 'sunucu'){ const res = await fetch('https://api.mcsrvstat.us/3/n1.1984.lol:6710'); const data = await res.json(); const { user } = interaction; const SunucuBilgi = new EmbedBuilder() .setTitle('Sunucu Bilgileri') .setDescription(data.online ? `**<:oyuncu:1183833674316271817> Sunucudaki Aktif Oyuncu Sayısı:** ${data.players.online} oyuncu aktif!` : "Sunucu aktif değil.") .setColor('#0099ff') .setFooter({ text: `${user.username} Tarafından İstendi`, iconURL: user.displayAvatarURL() }) await interaction.deferReply(); await interaction.editReply({ embeds: [SunucuBilgi], ephemeral: false})