[英]MessageEmbed field values must be non-empty strings gamedig problem
Hello i have a problem and its its if (typeof data !== 'string') throw new error(errorMessage);你好我有一个问题,它的 if (typeof data !== 'string') throw new error(errorMessage); RangeError [EMBED_FIELD_VALUE]: MessageEmbed field values must be non-empty strings.
RangeError [EMBED_FIELD_VALUE]:MessageEmbed 字段值必须是非空字符串。
i trying on players to put the amount of players that the minecraft server has like:我尝试让玩家输入我的世界服务器拥有的玩家数量:
Players Online: 79 Players在线玩家:79 名玩家
my code its:我的代码:
let state = null;
let jugadores = 0;
setInterval(() => {
Gamedig.query({
type: 'minecraft',
host: 'mc.latinplay.net',
port: '25565'
})
.then((updatedState) => {
state = updatedState;
players = state.players.length;
});
}, 6000);
module.exports = new Command({
name: cmdconfig.EstadoCommand,
description: cmdconfig.EstadoCommandDesc,
async run(interaction) {
const LatinStatus = new Discord.MessageEmbed()
.setColor('RANDOM')
.addField('**Players:**', 'players')
.addField('**Status**', "**Online💚**", true);
interaction.reply({
embeds: [LatinEstado],
});
}
},
);
Modify your code from your recent:从您最近的代码修改您的代码:
let state = null;
let jugadores = 0;
setInterval(() => {
Gamedig.query({
type: 'minecraft',
host: 'mc.latinplay.net',
port: '25565'
})
.then((updatedState) => {
state = updatedState;
players = state.players.length || "0"; //adding || operator so no error will occure
});
}, 6000);
module.exports = new Command({
name: cmdconfig.EstadoCommand,
description: cmdconfig.EstadoCommandDesc,
async run(interaction) {
const LatinStatus = new Discord.MessageEmbed()
.setColor('RANDOM')
.addField('**Players:**', 'players')
.addField('**Status**', "**Online💚**", true);
interaction.reply({
embeds: [LatinEstado],
});
}
},
);
Ive seen alot of errors in here, you can also use an operator called or
in operator ||
我在这里看到了很多错误,你也可以使用一个叫做
or
in operator ||
的运算符to prevent error when players
reached on 0
members.以防止
players
到达0
个成员时出错。
module.exports = new Command({
name: cmdconfig.EstadoCommand,
description: cmdconfig.EstadoCommandDesc,
async run(interaction) {
let state = null;
let jugadores = 0; //I also don't understand what is these for.
setInterval(() => {
Gamedig.query({
type: 'minecraft',
host: 'mc.latinplay.net',
port: '25565'
})
.then((updatedState) => {
state = updatedState;
players = state.players.length;
const LatinStatus = new Discord.MessageEmbed()
.setColor('RANDOM')
.addField('**Players:**', `${players}`) //also it must be `${players}`
.addField('**Status**', "**Online💚**", true);
interaction.reply({
embeds: [LatinEstado],
});
});
}, 6000);
}
},
);
EDIT:编辑:
I tried your code and caught an error such as Error: Failed all 1 attempts
我尝试了您的代码并发现了一个错误,例如
Error: Failed all 1 attempts
so you can use .catch
function所以你可以使用
.catch
功能
setInterval(() => {
Gamedig.query({
type: 'minecraft',
host: 'mc.latinplay.net',
port: '25565'
}).catch((err) => {
console.log() //or
console.log(err)
})
.then((updatedState) => {
state = updatedState;
players = state.players.length;
const LatinStatus = new Discord.MessageEmbed()
.setColor('RANDOM')
.addField('**Players:**', `${players || "0"}`) //also it must be `${players}`
.addField('**Status**', "**Online💚**", true);
interaction.reply({
embeds: [LatinEstado],
});
});
}, 6000);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.