Skip to content

Command Options

Each function takes the following parameters:

  • description: The description of the option.
  • required?: If the option is required.
  • value?: Callback where you can filter the value sent by discord before it reaches the main command. How to use here

Type Options

createStringOption

1
@Options({
2
choices: createStringOption({
3
choices: [
4
{ name: 'The best library', value: 'seyfert' },
5
{ name: 'An odd stuff', value: 'oceanicjs' }
6
]
7
}),
8
autocomplete: createStringOption({
9
autocomplete: (interaction) => {
10
const select = ['bugs', 'actions', 'random'];
11
const focus = interaction.getInput();
12
return interaction.respond(
13
select
14
.filter((ch) => ch.includes(focus))
15
.map((ch) => ({ name: ch, value: ch }))
16
);
17
}
18
}),
19
limitLength: createStringOption({
20
max_length: 500,
21
min_length: 200
22
})
23
})

createIntegerOption

1
@Options({
2
choices: createIntegerOption({
3
choices: [
4
{ name: 'seyfert', value: 1 },
5
{ name: '?discord.js', value: 2 },
6
{ name: '??oceanicjs', value: 3 }
7
]
8
}),
9
autocomplete: createIntegerOption({
10
autocomplete: (interaction) => {
11
const select = ['1651611', '4616165156549', '15616416515616'];
12
13
const focus = interaction.getInput();
14
15
return interaction.respond(
16
select
17
.filter((ch) => ch.includes(`${focus}`))
18
.map((ch) => ({ name: ch, value: parseInt(ch) }))
19
);
20
}
21
}),
22
limitValue: createIntegerOption({
23
max_value: 500,
24
min_value: 200
25
})
26
})

createNumberOption

1
@Options({
2
choices: createNumberOption({
3
choices: [
4
{ name: 'seyfert', value: 1 },
5
{ name: '?discord.js', value: 2 },
6
{ name: '??Oceanicjs', value: 3 }
7
]
8
}),
9
autocomplete: createNumberOption({
10
autocomplete: (interaction) => {
11
// imagine javascript Number or Integer kekw
12
const select = ['1651611', '4616165156549', '15616416515616'];
13
14
const focus = interaction.getInput();
15
16
return interaction.respond(
17
select
18
.filter((ch) => ch.includes(`${focus}`))
19
.map((ch) => ({ name: ch, value: parseInt(ch) }))
20
);
21
}
22
}),
23
limitValue: createNumberOption({
24
max_value: 500,
25
min_value: 200
26
})
27
})

createChannelOption

1
@Options({
2
channel: createChannelOption({
3
description: 'This is a channel option',
4
})
5
});
6
7
import { ChannelTypes } from 'seyfert/lib/types';
8
9
@Options({
10
channelTypes: createChannelOption({
11
description: 'This is a limited channel option',
12
channel_types: [ChannelTypes.GuildVoice]
13
})
14
});

createBooleanOption

1
@Options({
2
bool: createBooleanOption({
3
description: 'This is a boolean option',
4
required: true
5
})
6
});

createUserOption

1
@Options({
2
user: createUserOption({
3
description: 'This is a user option',
4
required: true
5
})
6
});

createRoleOption

1
@Options({
2
role: createRoleOption({
3
description: 'This is a role option',
4
required: true
5
})
6
});

createMentionableOption

1
@Options({
2
mentionable: createMentionableOption({
3
description: 'This is a mentionable option',
4
required: true
5
})
6
});

createAttachmentOption

1
@Options({
2
attachment: createAttachmentOption({
3
description: 'This is a attachment option',
4
required: true
5
})
6
});

Using the value callback

1
import { OKFunction } from 'seyfert';
2
3
@Options({
4
url: createStringOption({
5
description: 'how to be a gamer',
6
value(data, ok: OKFunction<URL>, fail) {
7
if (isUrl(data.value)) return ok(new URL(data.value));
8
fail('expected a valid url');
9
}
10
})
11
});

A briefly example was given in Creating your first command