Home > Mobile >  Select Menu Status Discord.js v14
Select Menu Status Discord.js v14

Time:07-20

Does not change the status of the bot, someone would help you with what the problem might be? The value of the variable "statuses" is status, but it does not change the status. If I write client.user.setStatus('dnd'); you can work, but so in this case it does not make much sense

status.js

const { SlashCommandBuilder, ActionRowBuilder, SelectMenuBuilder } = require('discord.js');

module.exports = {
    data: new SlashCommandBuilder()
    .setName('status')
    .setDescription('Set status'),
    async execute(interaction, client) {
        const actionRow = new ActionRowBuilder()
        .addComponents(
            new SelectMenuBuilder()
            .setCustomId('set-status')
            .setPlaceholder('Nothing is selected.')
            .setMinValues(1)
            .setMaxValues(1)
            .addOptions([
                {
                    label: `online`,
                    description: `Online status.`,
                    value: `online`
                },
                {
                    label: `idle`,
                    description: `Idle status.`,
                    value: `idle`
                },
                {
                    label: `dnd`,
                    description: `Do Not Disturb status.`,
                    value: `dnd`
                },
                {
                    label: `invisible`,
                    description: `Invisible status.`,
                    value: `invisible`
                },
            ])
        );

        await interaction.reply({ content: `Status? `, components: [actionRow] });
    },
};

interactionCreate.js

        } else if (interaction.isSelectMenu()) {
            if (interaction.customId == "set-status") {
                let statuses = "";
                await interaction.values.forEach(async value => {
                    statuses  = `${value} `
                });
                client.user.setStatus(statuses);
                const message = await interaction.deferReply({
                    fetchReply: true
                });
        
                const newMessage = `Status: ${statuses}`
                await interaction.editReply({
                    content: newMessage
                });
            }
        }
    },
};

Thank you!

CodePudding user response:

I'm not sure what you want to do with that interaction.values.forEach loop but you don't need that. Also, as you're creating a new array with the array items statuses = `${value} ` , you add an extra space in the status name, so these become something like "dnd " or "idle ".

interaction.values returns an array with a single value, the value of the selected menu item. You can just use interaction.values[0] in your setStatus().

I've just checked and the following works as expected:

if (interaction.isSelectMenu()) {
  if (interaction.customId == 'set-status') {
    let status = interaction.values[0];
    client.user.setStatus(status);

    await interaction.editReply({
      content: `Status updated to _"${status}"_`,
      components: [],
    });
  }
}
  • Related