Показать сообщение отдельно
  #1 (permalink)  
Старый 01.07.2019, 09:42
Новичок на форуме
Отправить личное сообщение для FinalDoomer Посмотреть профиль Найти все сообщения от FinalDoomer
 
Регистрация: 01.07.2019
Сообщений: 1

Помогите с ошибкой
Текст ошибки:

(node:5724) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'id' of undefined
at Client.bot.on (Z:\Slowpoke\index.js:23:45)
at Client.emit (events.js:203:15)
at MessageCreateHandler.handle (Z:\Slowpoke\node_modules\discord.js\src\client\we bsocket\packets\handlers\MessageCreate.js:9:34)
at WebSocketPacketManager.handle (Z:\Slowpoke\node_modules\discord.js\src\client\we bsocket\packets\WebSocketPacketManager.js:105:65)
at WebSocketConnection.onPacket (Z:\Slowpoke\node_modules\discord.js\src\client\we bsocket\WebSocketConnection.js:333:35)
at WebSocketConnection.onMessage (Z:\Slowpoke\node_modules\discord.js\src\client\we bsocket\WebSocketConnection.js:296:17)
at WebSocket.onMessage (Z:\Slowpoke\node_modules\ws\lib\event-target.js:120:16)
at WebSocket.emit (events.js:198:13)
at Receiver.receiverOnMessage (Z:\Slowpoke\node_modules\ws\lib\websocket.js:789: 20)
at Receiver.emit (events.js:198:13)
(node:5724) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:5724) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Код программы:

const Discord = require('discord.js');
const bot = new Discord.Client();

const {
prefix,
token,
} = require('./config.json');
const ytdl = require('ytdl-core');

bot.login("NTk0OTgyMDE1MTE2MjQ3MDY0.XRmP1g.cTO58Q7 SwFEU9aShAn3ebJY6m0A");

const queue = new Map();

bot.on('message', (message)=>{
if(message.content =="hip hip"){
message.reply("hooray!");
}
})
bot.on('message', async message =>{
if (message.author.bot) return;
if (!message.content.startsWith(prefix)) return;

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

if (message.content.startsWith(`${prefix}play`)) {
execute(message, serverQueue);
return;
} else if (message.content.startsWith(`${prefix}skip`)) {
skip(message, serverQueue);
return;
} else if (message.content.startsWith(`${prefix}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);
}

bot.login(token);
Ответить с цитированием