arda.nb01
Centipat
- Katılım
- 24 Ocak 2024
- Mesajlar
- 282
Daha fazla
- Cinsiyet
- Erkek
Merhaba bir müzik botu geliştiriyorum. Sistemi kurdum ve son sistemde kullanıcıların sisteme (playlist. JSON adlı dosyaya) çalma listesi kaydetme özelliği getirdim fakat kodumu çalıştırdığımda 403 hatası alıyorum.
Kod:
const { Client, Intents, MessageEmbed } = require('discord.js');
const { joinVoiceChannel, createAudioPlayer, createAudioResource, AudioPlayerStatus, VoiceConnectionStatus } = require('@discordjs/voice');
const ytdl = require('ytdl-core');
const { token, prefix } = require('./config.json');
const { savePlaylists, loadPlaylists } = require('./playlists');
const client = new Client({
intents: [
Intents.FLAGS.GUILDS,
Intents.FLAGS.GUILD_VOICE_STATES,
Intents.FLAGS.GUILD_MESSAGES,
]
});
let playlists = loadPlaylists(); // Bot başlatıldığında çalma listelerini yükle.
client.once('ready', () => {
console.log('Bot is ready!');
});
client.on('messageCreate', async message => {
if (!message.content.startsWith(prefix) || message.author.bot) return;
const args = message.content.slice(prefix.length).trim().split(/ +/);
const command = args.shift().toLowerCase();
const embed = new MessageEmbed()
.setColor('#0099ff')
.setAuthor('Discord Müzik Botu', '')
.setTimestamp()
.setFooter('Geliştirici: İsminiz', '');
if (command === 'çalmalistesioluştur') {
const playlistName = args.shift();
if (!playlistName) {
return message.channel.send(' bir çalma listesi ismi belirtin.');
}
if (!playlists[playlistName]) {
playlists[playlistName] = [];
savePlaylists(playlists);
message.channel.send(`Çalma listesi oluşturuldu: **${playlistName}**`);
} else {
message.channel.send('Bu isimde bir çalma listesi zaten mevcut.');
}
}
if (command === 'çalmaekle') {
const playlistName = args.shift();
const songUrls = args;
if (!playlistName || songUrls.length === 0) {
return message.channel.send(' bir çalma listesi ismi ve şarkı URL\'leri belirtin.');
}
if (!playlists[playlistName]) {
return message.channel.send('Bu isimde bir çalma listesi bulunamadı.');
}
for (const songUrl of songUrls) {
try {
const songInfo = await ytdl.getInfo(songUrl);
playlists[playlistName].push({
title: songInfo.videoDetails.title,
url: songUrl,
thumbnail: songInfo.videoDetails.thumbnails[0].url
});
savePlaylists(playlists);
embed.setDescription(`**${playlistName}** çalma listesine eklendi: [${songInfo.videoDetails.title}](${songUrl})`)
.setThumbnail(songInfo.videoDetails.thumbnails[0].url);
message.channel.send({ embeds: [embed] });
} catch (error) {
console.error(error);
message.channel.send(`Şarkı eklenirken bir hata oluştu: ${songUrl}`);
}
}
}
if (command === 'çalmalistesi') {
const playlistName = args.shift();
if (!playlistName) {
return message.channel.send(' bir çalma listesi ismi belirtin.');
}
if (!playlists[playlistName]) {
return message.channel.send('Bu isimde bir çalma listesi bulunamadı.');
}
let description = '';
playlists[playlistName].forEach((song, index) => {
description += `${index + 1}. [${song.title}](${song.url})\n`;
});
embed.setTitle(`Çalma Listesi: ${playlistName}`)
.setDescription(description)
.setThumbnail(playlists[playlistName][0].thumbnail);
message.channel.send({ embeds: [embed] });
}
if (command === 'oynat') {
const playlistName = args.shift();
if (!playlistName) {
return message.channel.send(' bir çalma listesi ismi belirtin.');
}
if (!playlists[playlistName]) {
return message.channel.send('Bu isimde bir çalma listesi bulunamadı.');
}
const voiceChannel = message.member.voice.channel;
if (!voiceChannel) {
return message.channel.send('bir ses kanalına katılın.');
}
const connection = joinVoiceChannel({
channelId: voiceChannel.id,
guildId: message.guild.id,
adapterCreator: message.guild.voiceAdapterCreator,
});
connection.on(VoiceConnectionStatus.Ready, () => {
console.log('The bot has connected to the channel!');
});
const player = createAudioPlayer();
connection.subscribe(player);
let songQueue = [...playlists[playlistName]];
const playSong = async () => {
if (songQueue.length === 0) {
connection.destroy();
return;
}
const currentSong = songQueue.shift();
try {
const stream = ytdl(currentSong.url, { filter: 'audioonly', quality: 'highestaudio' });
const resource = createAudioResource(stream);
player.play(resource);
embed.setDescription(`Şu anda oynatılıyor: [${currentSong.title}](${currentSong.url})`)
.setThumbnail(currentSong.thumbnail);
message.channel.send({ embeds: [embed] });
} catch (error) {
console.error(error);
message.channel.send(`Şarkı çalınırken bir hata oluştu: ${currentSong.url}`);
}
};
player.on(AudioPlayerStatus.Idle, playSong);
player.on('error', error => {
console.error(error);
playSong();
});
playSong();
}
if (command === 'karıştır') {
const playlistName = args.shift();
if (!playlistName) {
return message.channel.send(' bir çalma listesi ismi belirtin.');
}
if (!playlists[playlistName]) {
return message.channel.send('Bu isimde bir çalma listesi bulunamadı.');
}
playlists[playlistName] = playlists[playlistName].sort(() => Math.random() - 0.5);
savePlaylists(playlists);
message.channel.send(`Çalma listesi karıştırıldı: **${playlistName}**`);
}
if (command === 'çalmagüncelle') {
const playlistName = args.shift();
const songUrls = args;
if (!playlistName || songUrls.length === 0) {
return message.channel.send(' bir çalma listesi ismi ve şarkı URL\'leri belirtin.');
}
if (!playlists[playlistName]) {
return message.channel.send('Bu isimde bir çalma listesi bulunamadı.');
}
playlists[playlistName] = [];
for (const songUrl of songUrls) {
try {
const songInfo = await ytdl.getInfo(songUrl);
playlists[playlistName].push({
title: songInfo.videoDetails.title,
url: songUrl,
thumbnail: songInfo.videoDetails.thumbnails[0].url
});
savePlaylists(playlists);
embed.setDescription(`**${playlistName}** çalma listesi güncellendi: [${songInfo.videoDetails.title}](${songUrl})`)
.setThumbnail(songInfo.videoDetails.thumbnails[0].url);
message.channel.send({ embeds: [embed] });
} catch (error) {
console.error(error);
message.channel.send(`Şarkı eklenirken bir hata oluştu: ${songUrl}`);
}
}
}
if (command === 'çal') {
const songUrl = args.shift();
if (!songUrl) {
return message.channel.send(' bir şarkı URL\'si belirtin.');
}
const voiceChannel = message.member.voice.channel;
if (!voiceChannel) {
return message.channel.send(' bir ses kanalına katılın.');
}
const connection = joinVoiceChannel({
channelId: voiceChannel.id,
guildId: message.guild.id,
adapterCreator: message.guild.voiceAdapterCreator,
});
connection.on(VoiceConnectionStatus.Ready, async () => {
console.log('The bot has connected to the channel!');
try {
const songInfo = await ytdl.getInfo(songUrl);
const stream = ytdl(songUrl, { filter: 'audioonly', quality: 'highestaudio' });
const resource = createAudioResource(stream);
const player = createAudioPlayer();
player.play(resource);
connection.subscribe(player);
embed.setDescription(`Şu anda oynatılıyor: [${songInfo.videoDetails.title}](${songUrl})`)
.setThumbnail(songInfo.videoDetails.thumbnails[0].url);
message.channel.send({ embeds: [embed] });
player.on(AudioPlayerStatus.Idle, () => {
connection.destroy();
});
player.on('error', error => {
console.error(error);
connection.destroy();
});
} catch (error) {
console.error(error);
message.channel.send(`Şarkı çalınırken bir hata oluştu: ${songUrl}`);
}
});
}
});
client.login(token);
Son düzenleyen: Moderatör: