Javascript.RU

Создать новую тему Ответ
 
Опции темы Искать в теме
  #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);
Ответить с цитированием
  #2 (permalink)  
Старый 19.08.2019, 17:42
Новичок на форуме
Отправить личное сообщение для nevikat Посмотреть профиль Найти все сообщения от nevikat
 
Регистрация: 26.05.2019
Сообщений: 5

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

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

В последней строке const serverQueue = queue.get(message.guild.id);
Ответить с цитированием
  #3 (permalink)  
Старый 21.08.2019, 10:53
Аватар для рони
Профессор
Отправить личное сообщение для рони Посмотреть профиль Найти все сообщения от рони
 
Регистрация: 27.05.2010
Сообщений: 33,064

FinalDoomer,
Пожалуйста, отформатируйте свой код!

Для этого его можно заключить в специальные теги: js/css/html и т.п., например:
[html run]
... минимальный код страницы с вашей проблемой
[/html]

О том, как вставить в сообщение исполняемый javascript и html-код, а также о дополнительных возможностях форматирования - читайте http://javascript.ru/formatting.
Ответить с цитированием
Ответ



Опции темы Искать в теме
Искать в теме:

Расширенный поиск


Похожие темы
Тема Автор Раздел Ответов Последнее сообщение
Помогите разобраться с ошибкой в коде kinoda Элементы интерфейса 11 24.05.2016 18:58
Помогите с ошибкой! Vollanddzaft (X)HTML/CSS 3 15.07.2015 10:33
Пожалуйста, Помогите разобраться с ошибкой Gradu Firefox/Mozilla 5 01.06.2015 09:18
Код калькулятора на JS. помогите с ошибкой! kirill.psl Общие вопросы Javascript 9 26.08.2010 11:38
Помогите! Почему в Opera js-код работает с ошибкой. В IE все нормально. maxonline Events/DOM/Window 4 21.11.2008 12:39