Я пытаюсь создать массив, содержащий псевдонимы и имена команд, однако, когда имя с 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] } },
command.aliases
это массив. Для purge
команды этот массив имеет один ключ ( 0
) и одно значение ( 'delete'
). Поэтому, когда вы используете, command.aliases.keys( )
вы получаете индексы массива, а не значение.
Просто используйте command.aliases
вместо этого сам массив ( ):
const commands = collection.reduce((all, command) => [...all, command.name, ...(command.aliases
? command.aliases
: [])], []);
Примечание. Это не имеет ничего общего с ключевым словом 'delete'
. Вы получите такое же поведение для любых псевдонимов.
Este artículo se recopila de Internet, indique la fuente cuando se vuelva a imprimir.
En caso de infracción, por favor [email protected] Eliminar
Déjame decir algunas palabras