[英]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 个参数: message
和args
。 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.