gpt4 book ai didi

javascript - Discord.js 机器人 "Unhanded Promised Rejection Type Error: Cannot Read Property 255890520990154752 of undefined"

转载 作者:行者123 更新时间:2023-12-02 22:48:04 24 4
gpt4 key购买 nike

const commando = require('discord.js-commando');
const ytdl = require('ytdl-core');

function Play(connection, message)
{
var servers = servers[message.guild.id];
server.dispatcher = connection.playStream(ytdl(`${server.queue[0]}`, {filter: "audioonly"}));
server.queue.shift();
server.dispatcher.on("end", function(){
if(server.queue[0])
{
Play(connection, message);
}else
{
connection.disconnect();
}
});

}

class PlayCommand extends commando.Command
{
constructor(client)
{
super(client,{
name: 'play',
group: 'music',
memberName: 'play',
description: 'Plays music!'
});
}

async run(message, args)
{
if (!permissions.has('CONNECT') || !permissions.has('SPEAK')) {
return message.channel.send('I need the permissions to join and speak in your voice channel!');
}

if(message.member.voiceChannel)
{
if(!message.guild.voiceConnection)
{
if(!servers[message.guild.id])
{
var server = servers[message.guild.id];
servers[message.guild.id] = {queue: []}
}
message.member.voiceChannel.join()
.then(connection => {
var servers = servers[message.guild.id];
message.reply("Sucessfully Joined Channel!");

let validate = await ytdl.validateURL(args);
if(!validate) return message.channel.send('Sorry, Please input a **valid** url.');

server.queue.push(args);
Play(connection, message);
})
}
}
else{
message.reply("You must be in a voice channel to use that command! ")
}

console.log(message.author.username + ' Used a ' + 'music' + ' command \n');
}
}

module.exports = PlayCommand;

这是机器人上“播放”命令的代码。机器人的工作是使用 ytdl 库播放音乐。

我不确定问题出在哪里;起初,我认为可能没有找到库或安装错误,所以我重新安装了所有库(ytdl-core、discord.js、discord.js-commando...)

还是什么都没有!

我对 Javascript 不太熟悉,尤其是错误代码,因此非常感谢任何帮助或指导正确方向来帮助解决问题!

这是我在这里提出的第一个问题,因此对于任何不一致之处我深表歉意。

完整的错误代码:

(node:18216) [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.

最佳答案

看起来您的servers变量可能从未初始化过。确保它确实包含正确的公会。

关于javascript - Discord.js 机器人 "Unhanded Promised Rejection Type Error: Cannot Read Property 255890520990154752 of undefined",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58299989/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com