简体   繁体   English

遇到 TypeError:无法读取 Discord.JS 中未定义的属性“0”

[英]Encountering TypeError: Cannot read property '0' of undefined in Discord.JS

I am trying to do a "jumbo command", but when I use the command I encounter the following error:我正在尝试执行“巨型命令”,但是当我使用该命令时遇到以下错误:

TypeError: Cannot read property '0' of undefined

Here's my code:这是我的代码:

const Discord = require("discord.js");
const client = new Discord.Client();
const { Client, MessageEmbed } = require("discord.js");

module.exports = {
    name: "jumbo",
    description: "",
    execute(client, message, args) {
        if (!args[0]) return message.channel.send("Debes escribir un emoji.");

        let emoji = message.guild.emojis.cache.find((x) => x.name === args[0].split(":")[1]);

        if (!emoji) return message.channel.send("Ese no es un emoji válido.");

        const embed = new Discord.MessageEmbed().setTitle("Emoji:").setImage(emoji.url).setColor("RANDOM");

        message.channel.send(embed);
    },
};

According to the Command handling page of the Discord.js Guide , a well-formed exported module's execute method only has 2 arguments: message , and args .根据Discord.js 指南命令处理页面,格式良好的导出模块的execute方法只有 2 个参数: messageargs client does not appear to be supported as you seem to think it is. client似乎不像您认为的那样受支持。 This is in line with args being undefined: no parameter at this position will be set and will thus be undefined , and would cause errors similar to/the same as the one you're currently encountering.这与args未定义一致:在此位置不会设置任何参数,因此将是undefined ,并且会导致与您当前遇到的错误类似/相同的错误。

The aforementioned page specifically mentions how you can grab the instance of client for use in your code:上述页面特别提到了如何获取客户端实例以在代码中使用:

TIP小费

If you need to access your client instance from inside one of your command files, you can access it via message.client .如果您需要从您的命令文件之一访问您的客户端实例,您可以通过message.client访问它。 [...] [...]

暂无
暂无

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

相关问题 类型错误:无法读取未定义的 discord.js 的属性“用户名” - TypeError: Cannot read property 'username' of undefined discord.js Discord.js | 类型错误:无法读取未定义的属性“声音” - Discord.js | TypeError: Cannot read property 'voice' of undefined TypeError:无法读取未定义的discord.js的属性“ add” - TypeError: Cannot read property 'add' of undefined discord.js Discord.js 错误 - 类型错误:无法读取未定义的属性“执行” - Discord.js Error - TypeError: Cannot read property 'execute' of undefined Discord.js | UnhandledPromiseRejectionWarning:TypeError:无法读取未定义的属性“部分” - Discord.js | UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'partial' of undefined 类型错误:无法读取未定义 Discord.js 的属性“id” - TypeError: Cannot read property 'id' of undefined Discord.js 类型错误:无法读取未定义的属性“添加”,Discord.JS - TypeError: Cannot read property 'add' of undefined, Discord.JS 类型错误:无法读取未定义 Discord.js 的属性“天” - TypeError: Cannot read property 'day' of undefined Discord.js TypeError:无法读取未定义的属性“执行”(Discord.js) - TypeError: Cannot read property 'execute' of undefined (Discord.js) UnhandledPromiseRejectionWarning:TypeError:无法读取未定义 Discord.JS 的属性“forEach” - UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'forEach' of undefined Discord.JS
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM