Я пытаюсь получить все текстовые каналы в гильдии и перечислить их в меню выбора, и у меня возникают проблемы.
Вот мой код:
const { PermissionOverwrites, Permissions, Collection, MessageEmbed, MessageActionRow, MessageSelectMenu } = require("discord.js");
const dotenv = require("dotenv");
dotenv.config();
module.exports = {
data: {
name: `select-raid-options`
},
async execute (interaction) {
let guild = interaction.client.guilds.cache.get(process.env.GUILD_ID);
switch (interaction.values[0]) {
case 'raid_channel':
let raidChannel = guild.channels.cache.find(channel => channel.name === 'raid');
raidChannel.send('Raid');
break;
case 'select_channel':
// Create the Embed Message
const channelSelectorMessage = new MessageEmbed()
.setColor('#e4e8eb')
.setTitle('Veuillez sélectionnez le channel où vous souhaitez publier votre raid.')
.setTimestamp()
// Create the Select Menu
let channelSelectorSelect = new MessageSelectMenu()
.setCustomId('select-raid-channel')
.setPlaceholder('Nothing selected')
.addOptions([
{
label: `Annuler`,
description: 'Annulez la publication de votre raid.',
value: 'cancel',
},
]);
// Get all channels in the guild
guild.channels.cache.forEach(channel => {
// Check if the channel is not the raid channel
if (channel.name !== 'raid') {
// add channel to the select menu
channelSelectorSelect.addOptions([
{
label: `${channel.name}`, // Option label
description: `${channel.name}`, // Option description
value: `${channel.id}`, // Option value
},
]);
}
})
console.info(channelSelectorSelect); // Debug to see the select menu
interaction.user.send({embeds: [channelSelectorMessage], components: [channelSelectorSelect]}); // Send the message with the select menu to the user
}
await interaction.reply({ content:'Information envoyée !', ephemeral: true });
}
}
console.info каналаSelectorSelect возвращает мне это:
MessageSelectMenu {
type: 'SELECT_MENU',
customId: 'select-raid-channel',
placeholder: 'Nothing selected',
minValues: null,
maxValues: null,
options: [
{
label: 'Annuler',
value: 'cancel',
description: 'Annulez la publication de votre raid.',
emoji: null,
default: false
},
{
label: '?- ????????????',
value: '953674264408653825',
description: '?- ????????????',
emoji: null,
default: false
},
{
label: '???̀????',
value: '953674264408653826',
description: '???̀????',
emoji: null,
default: false
},
{
label: '?????????',
value: '953674264408653827',
description: '?????????',
emoji: null,
default: false
},
{
label: '? - ????????? ???????',
value: '954015397336735807',
description: '? - ????????? ???????',
emoji: null,
default: false
},
{
label: '???????????',
value: '954015876892475433',
description: '???????????',
emoji: null,
default: false
},
{
label: '???́???????????',
value: '954015934081794128',
description: '???́???????????',
emoji: null,
default: false
},
{
label: '??????????',
value: '954016142844895302',
description: '??????????',
emoji: null,
default: false
},
{
label: '??????????',
value: '954016204966727680',
description: '??????????',
emoji: null,
default: false
},
{
label: '? - ??????? ???????',
value: '954020253757739018',
description: '? - ??????? ???????',
emoji: null,
default: false
},
{
label: '3wa',
value: '963018402132267048',
description: '3wa',
emoji: null,
default: false
},
{
label: 'tickets',
value: '963018417936420895',
description: 'tickets',
emoji: null,
default: false
},
{
label: 'Degré Zero',
value: '973526523200016384',
description: 'Degré Zero',
emoji: null,
default: false
},
{
label: 'test-commands',
value: '973528693714595860',
description: 'test-commands',
emoji: null,
default: false
}
],
disabled: false
}
И когда я отправляю сообщение с селектором, я получаю эту ошибку:
DiscordAPIError: Invalid Form Body components[0]: The specified component type is invalid in this context
Если у кого-то есть идея, как это исправить?
Спасибо
Вам нужно добавить меню выбора в строку действий. Если вы не знаете, как это сделать, посетите этот страница в руководстве Discord.js.
Другой ответ правильный, я решил поставить код, так как эта страница не демонстрирует, как динамически добавлять параметры.
// Create the Message Action row
let channelSelectorSelect = new MessageActionRow()
.addComponents(
new MessageSelectMenu()
.setCustomId('select-raid-channel')
.setPlaceholder('Nothing selected')
.addOptions([{
label: `Annuler`,
description: 'Annulez la publication de votre raid.',
value: 'cancel',
}]);
)
guild.channels.cache.forEach(channel => {
if (channel.name !== 'raid') {
// add channel to the select menu - the below line was changed
channelSelectorSelect.components[0].addOptions([{
label: `${channel.name}`,
description: `${channel.name}`,
value: `${channel.id}`,
}]);
}
})