mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-23 19:49:50 +02:00
feat: added all buttons to dynamic commands
This commit is contained in:
1 parent
dd39563d6d
commit
d1d8aad6c7
9 files changed
+157
-57
No files matched your search
@@ -1,20 +1,33 @@
|
||||
import { CacheType, ChatInputCommandInteraction } from 'discord.js';
|
||||
import {
|
||||
CacheType,
|
||||
ChatInputCommandInteraction,
|
||||
CommandInteractionOption,
|
||||
} from 'discord.js';
|
||||
|
||||
export interface Parameters {
|
||||
[key: string]: CommandInteractionOption['value'] | undefined | null;
|
||||
}
|
||||
|
||||
export default function interactionToURL(
|
||||
interaction: ChatInputCommandInteraction<CacheType>,
|
||||
parameters?: Parameters,
|
||||
) {
|
||||
const pathname = [
|
||||
interaction.commandName,
|
||||
interaction.options.getSubcommandGroup(),
|
||||
interaction.options.getSubcommand(),
|
||||
interaction.options.getSubcommandGroup(false),
|
||||
interaction.options.getSubcommand(false),
|
||||
]
|
||||
.filter(Boolean)
|
||||
.join('/');
|
||||
const urlSearchParams = new URLSearchParams();
|
||||
const params = [
|
||||
...interaction.options.data.map(
|
||||
(option) => [option.name, option.value] as const,
|
||||
),
|
||||
...Object.entries(parameters ?? {}),
|
||||
]
|
||||
.filter(([, value]) => value !== undefined && value !== null)
|
||||
.map(([key, value]) => `${key}=${value}`)
|
||||
.join('&');
|
||||
|
||||
interaction.options.data.forEach((option) => {
|
||||
if (option.value) urlSearchParams.set(option.name, `${option.value}`);
|
||||
});
|
||||
|
||||
console.log(`${urlSearchParams}`);
|
||||
return `${pathname}${params.length > 0 ? `?${params}` : ''}`;
|
||||
}
|
||||
Reference in new issue
Block a user