我正在尝试创建一个包含命令别名和名称的数组,但是当存在带有delete
的名称时,它将在最终数组中将该值设置为0
const commands = collection.reduce((all, command) => [...all, command.name, ...(command.aliases
? command.aliases.keys()
: [])], []);
如何忽略delete关键字以使最终输出中的单词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] } },
答案 0 :(得分:3)
command.aliases
是一个数组。对于purge
命令,该数组具有一个键(0
)和一个值('delete'
)。因此,当您使用command.aliases.keys( )
时,您将获得数组的索引,而不是值。
只需使用数组本身(command.aliases
):
const commands = collection.reduce((all, command) => [...all, command.name, ...(command.aliases
? command.aliases
: [])], []);
注意:这与关键字'delete'
无关。对于任何别名,您都会得到相同的行为。