Мой музыкальный бот в Discord не работает. Не получаю командыJAVA

Программисты JAVA общаются здесь
Ответить Пред. темаСлед. тема
Anonymous
 Мой музыкальный бот в Discord не работает. Не получаю команды

Сообщение Anonymous »

Я пытался разработать музыкального бота для Discord вместо использования других ботов. Вот мой код:

Код: Выделить всё

const Discord = require('discord.js');
const {
prefix,
token,
} = require('./config.json');
const ytdl = require('ytdl-core');
const { CLient, GatewayIntentBits } = require('discord.js')
const client = new Discord.Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent,
GatewayIntentBits.GuildMembers,
],
});
const queue = new Map();

client.once('ready', () => {
console.log('Ready!');
});

client.once('reconnecting', () => {
console.log('Reconnecting!');
});

client.once('disconnect', () => {
console.log('Disconnect!');
});

client.on('message', async message => {
console.log('Message recieved')
if (message.author.bot) return;
if (!message.content.startsWith(prefix)) return;

const serverQueue = queue.get(message.guild.id);

if (message.content.startsWith(`!play`)) {
execute(message, serverQueue);
return;
} else if (message.content.startsWith(`!skip`)) {
skip(message, serverQueue);
return;
} else if (message.content.startsWith(`!stop`)) {
stop(message, serverQueue);
return;
} else {
message.channel.send('You need to enter a valid command!')
}
});

async function execute(message, serverQueue) {
const args = message.content.split(' ');

const voiceChannel = message.member.voiceChannel;
if (!voiceChannel) return message.channel.send('You need to be in a voice channel to play music!');
const permissions = voiceChannel.permissionsFor(message.client.user);
if (!permissions.has('CONNECT') || !permissions.has('SPEAK')) {
return message.channel.send('I need the permissions to join and speak in your voice channel!');
}

const songInfo = await ytdl.getInfo(args[1]);
const song = {
title: songInfo.title,
url: songInfo.video_url,
};

if (!serverQueue) {
const queueContruct = {
textChannel: message.channel,
voiceChannel: voiceChannel,
connection: null,
songs: [],
volume: 5,
playing: true,
};

queue.set(message.guild.id, queueContruct);

queueContruct.songs.push(song);

try {
var connection = await voiceChannel.join();
queueContruct.connection = connection;
play(message.guild, queueContruct.songs[0]);
} catch (err) {
console.log(err);
queue.delete(message.guild.id);
return message.channel.send(err);
}
} else {
serverQueue.songs.push(song);
console.log(serverQueue.songs);
return message.channel.send(`${song.title} has been added to the queue!`);
}

}

function skip(message, serverQueue) {
if (!message.member.voiceChannel) return message.channel.send('You have to be in a voice channel to stop the music!');
if (!serverQueue) return message.channel.send('There is no song that I could skip!');
serverQueue.connection.dispatcher.end();
}

function stop(message, serverQueue) {
if (!message.member.voiceChannel) return message.channel.send('You have to be in a voice channel to stop the music!');
serverQueue.songs = [];
serverQueue.connection.dispatcher.end();
}

function play(guild, song) {
const serverQueue = queue.get(guild.id);

if (!song) {
serverQueue.voiceChannel.leave();
queue.delete(guild.id);
return;
}

const dispatcher = serverQueue.connection.playStream(ytdl(song.url))
.on('end', () => {
console.log('Music ended!');
serverQueue.songs.shift();
play(guild, serverQueue.songs[0]);
})
.on('error', error =>  {
console.error(error);
});
dispatcher.setVolumeLogarithmic(serverQueue.volume / 5);
}

client.login(token);
В config.json у меня есть только переменная токена и префикс var, но сейчас я не использую префикс var.
Когда я запускаю этот скрипт, мой бот подключается к сети в Discord, но не Не получаю команды, настроил тестовый вывод, но оказалось, что функция обработки сообщений не работает. Как вы думаете, в чем может быть проблема?
В качестве префикса команды я использую "!".

Подробнее здесь: https://stackoverflow.com/questions/790 ... g-commands
Реклама
Ответить Пред. темаСлед. тема

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

  • Похожие темы
    Ответы
    Просмотры
    Последнее сообщение
  • Музыкальный бот Discord, когда я пропускаю трек, бот пропускает сразу 2 трека
    Anonymous » » в форуме Python
    0 Ответы
    38 Просмотры
    Последнее сообщение Anonymous
  • Музыкальный бот Discord не подключается к голосовому каналу
    Anonymous » » в форуме Python
    0 Ответы
    52 Просмотры
    Последнее сообщение Anonymous
  • Почему мой музыкальный дискорд-бот на Python звучит так плохо?
    Гость » » в форуме Python
    0 Ответы
    72 Просмотры
    Последнее сообщение Гость
  • Музыкальный бот nextcord.py, как играть в очередь
    Anonymous » » в форуме Python
    0 Ответы
    51 Просмотры
    Последнее сообщение Anonymous
  • Бот Discord.py отправляет файл на канал Discord
    Anonymous » » в форуме Python
    0 Ответы
    29 Просмотры
    Последнее сообщение Anonymous

Вернуться в «JAVA»