简体   繁体   English

“ TypeError:无法读取未定义的属性'push'” discord.js

[英]“TypeError: Cannot read property 'push' of undefined” discord.js

I've this complete error: 我有这个完整的错误:

 (node:9352) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'push' of undefined at Object.exports.run (C:\\users\\Cocoloco2005\\Desktop\\peterbot\\commands\\play.js:24:16) at processTicksAndRejections (internal/process/next_tick.js:81:5) (node:9352) 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:9352) [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. 

This is an issue that happened to my creating my discord bot, with Discord.js, in the "play" command 这是我在“播放”命令中使用Discord.js创建Discord机器人时发生的一个问题

(Full command here: (完整命令在这里:

 const ytdl = require('ytdl-core'); exports.run = async (client, message, args, ops) => { if (!message.member.voiceChannel) return message.channel.send('Connectes toi à un salon vocal'); if (!args[0]) return message.channel.send('Entres une URL'); let validate = await ytdl.validateURL(args[0]); if (!validate) { let commandFile = require('./search.js'); return commandFile.run(client, message, args, ops); } let info = await ytdl.getInfo(args[0]); let data = ops.active = (message.guild.id) || {}; if (!data.connection) data.connection = await message.member.voiceChannel.join(); if(!data.queue) data.queue = []; data.guildID = message.guild.id; data.queue.push[0]({ songTitle: info.title, requester: message.author.tag, url: args[0], announceChannel: message.channel.id }); if (!data.dispatcher) play(client, ops, data); else { message.channel.send(`Added to queue: ${info.title} | requested by: ${message.author.id}`) } ops.active.set(message.guild.id, data); } async function play(client, ops, data) { client.channels.get(data.queue[0].announceChannel).send(`Now Playing: ${data.queue[0].songTitle} | Requested by: ${data.queue[0].requester}`); data.dispatcher = await data.connection.playStream(ytdl(data.queue[0].url, {filter: 'audioonly'})); data.dispatcher.guildID = data.guildID; data.dispatcher.once('end', function() { end(client, ops, this); }); } function end(client, ops, dispatcher){ let fetched = ops.active.get(dispatcher.guildID); fetched.queue.shift(); if (fetched.queue.length > 0) { ops.active.set(dispatcher.guildID, fetched); play(client, ops, fetched); } else { ops.active.delete(dispatcher.guildID); let vc = client.guilds.get(dispatcher.guildID).me.voiceChannel; if (vc) vc.leave(); } } 

I don't know what to do, I didn't try anything "especial" because I'm new with Javascript. 我不知道该怎么做,我没有尝试任何“特别的”操作,因为我是Java语言的新手。 I tried to search but I don't find anything about people having my error. 我尝试搜索,但没有发现任何有关我的错误的信息。

Your error is in this block: 您的错误在以下代码段中:

data.queue.push[0]({
    songTitle: info.title,
    requester: message.author.tag,
    url: args[0],
    announceChannel: message.channel.id

});

Unless push is an index-able property of queue , that first line is probably the issue. 除非pushqueue的可索引属性,否则第一行可能是问题。 It seems to me that you might have accidentally added the [0] , since this would be a valid statement without it. 在我看来,您可能不小心添加了[0] ,因为如果没有它,这将是一个有效的声明。 I hope this helps! 我希望这有帮助!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 类型错误:无法读取未定义 Discord.js javascript 的属性“添加” - TypeError: Cannot read property 'add' of undefined Discord.js javascript 类型错误:无法读取未定义的属性 'has' // Discord.js - TypeError: Cannot read property 'has' of undefined // Discord.js 遇到 TypeError:无法读取 Discord.JS 中未定义的属性“0” - Encountering TypeError: Cannot read property '0' of undefined in Discord.JS Discord.JS UnhandledPromiseRejectionWarning:TypeError:无法读取未定义的属性“startsWith” - Discord.JS UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'startsWith' of undefined TypeError:无法读取未定义的属性“数据”| discord.js - TypeError: Cannot read property 'data' of undefined | discord.js 类型错误:无法读取未定义的属性“角色”|| Discord.js - TypeError: Cannot read property 'roles' of undefined || Discord.js (Discord.js)TypeError:无法读取未定义的属性“添加” - (Discord.js) TypeError: Cannot read property 'add' of undefined Discord.js:类型错误:无法读取未定义的属性“删除” - Discord.js : TypeError: Cannot read property 'remove' of undefined Discord.js“类型错误:无法读取未定义的属性‘有’” - Discord.js "TypeError: Cannot read property 'has' of undefined" discord.js错误TypeError:无法读取未定义的属性“ voiceChannel” - discord.js Error TypeError: Cannot read property 'voiceChannel' of undefined
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM