你好我有一個問題,它 的 if (typeof data !== 'string') throw new error(errorMessage); RangeError [EMBED_FIELD_VALUE]:MessageEmbed 欄位值必須是非空字串。
我嘗試讓玩家輸入我的世界服務器擁有的玩家數量:
在線玩家:79 名玩家
我的代碼:
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],
});
}
},
);
uj5u.com熱心網友回復:
從您最近的代碼修改您的代碼:
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],
});
}
},
);
我在這里看到了很多錯誤,您還可以使用在運算子中呼叫or的運算子||來防止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);
}
},
);
編輯:
我嘗試了您的代碼并發現了一個錯誤,例如Error: Failed all 1 attempts
所以你可以使用.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);
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/496264.html
標籤:javascript 不和谐 不和谐.js 游戏挖掘
