Js调用功能期间的可选选项


bot.commands.others.ping({
lang: "tr",
client: client,
type: msg,
});
async function cmd({ lang, client, type, content, embed }) {
if (!embed) embed = false;
embed = {};
if (embed) type.reply("yes");
if (!content) content = `Pong! ${client.ws.ping}ms !`;
type.reply(`${content}`);
}
module.exports = cmd;

这是我的代码,我想做optinal嵌入选择需要帮助!

如用户键入

client: 
type:
embed: ({title: 'smth'})

消息将与嵌入一起发送

使用Object.assignspread operator

const defaults = { v1: 'hello', v2: 'world' }
const input = { v1: 'hi'}
const merged = Object.assign( {}, defaults, input )
const merged = {...defaults, ...input}

在这两种情况下,默认值都将被覆盖。

最新更新