gpt4 book ai didi

javascript - 如何忽略删除关键字?

转载 作者:行者123 更新时间:2023-12-01 01:00:23 31 4
gpt4 key购买 nike

我正在尝试创建一个包含命令别名和名称的数组,但是当存在带有 delete 的名称时,它会将最终数组中的值设置为 0

const commands = collection.reduce((all, command) => [...all, command.name, ...(command.aliases
? command.aliases.keys()
: [])], []);

如何忽略删除关键字以在最终输出中获取单词“delete”而不是 0?

一些示例输出

Collection [Map] {
'purge' => { name: 'purge',
description: 'Delete multiple messages at a time (up to 99).',
category: 'Admin',
usage: '<amount>',
examples: [ '5', '99' ],
aliases: [ 'delete' ],
args: true,
guildOnly: true,
execute: [Function: execute],
default:
{ name: 'purge',
description: 'Delete multiple messages at a time (up to 99).',
category: 'Admin',
usage: '<amount>',
examples: [Array],
aliases: [Array],
args: true,
guildOnly: true,
execute: [Function: execute] } },
'setjoin' => { name: 'setjoin',
description:
'Sets a message which will be sent when a new user joins the server.',
category: 'Admin',
usage: '<message>',
examples:
[ 'Welcome to the server {{member}}',
'User {{tag}} joined the server' ],
args: true,
guildOnly: true,
execute: [Function: execute],
default:
{ name: 'setjoin',
description:
'Sets a message which will be sent when a new user joins the server.',
category: 'Admin',
usage: '<message>',
examples: [Array],
args: true,
guildOnly: true,
execute: [Function: execute] } },

最佳答案

command.aliases是一个数组。对于purge命令该数组有一个键( 0 )和一个值( 'delete' )。所以当你使用command.aliases.keys( )时您得到的是数组的索引,而不是值。

只需使用数组本身( command.aliases )即可:

const commands = collection.reduce((all, command) => [...all, command.name, ...(command.aliases
? command.aliases
: [])], []);

注意:这与关键字'delete'无关。对于任何别名,您都会得到相同的行为。

关于javascript - 如何忽略删除关键字?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56137302/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com