Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Poll not being created on slash command interaction #10258

Closed
IslandRhythms opened this issue May 6, 2024 · 4 comments
Closed

Poll not being created on slash command interaction #10258

IslandRhythms opened this issue May 6, 2024 · 4 comments

Comments

@IslandRhythms
Copy link

IslandRhythms commented May 6, 2024

Which package is this bug report for?

discord.js

Issue description

  1. use /poll
  2. observe no poll created

image
I believe this to be a bug because if I omit the content property and just attempt to create a poll, it throws a discord api error stating content is required. So it feels as though it acknowledges the poll property but is doing nothing with it.

Code sample

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

const { emojiCharacters } = require('../../resources/constants');


module.exports = {
  data: new SlashCommandBuilder().setName('poll').setDescription('starts a poll on the given topic')
  .addStringOption(option => option.setName('question').setDescription('the topic in the form of a question').setRequired(true))
  .addStringOption(option => option.setName('choices').setDescription('the possible choices, max 10, for the poll in the form of comma separated values'))
  .addRoleOption(option => option.setName('audience').setDescription('the people intended to respond to the poll'))
  .addBooleanOption(option => option.setName('multiple').setDescription('true to allow multiple answers. Default is no.'))
  .addNumberOption(option => option.setName('duration').setDescription('how long, in hours, the poll should remain active.')),
  async execute(interaction) {
    await interaction.deferReply();
    const message = {
      poll: {
        question: {
          text: interaction.options.getString('question')
        },
        duration: interaction.options.getNumber('duration') ?? 1, // duration in hours, minimum 1
        allowMultiselect: interaction.options.getBoolean('multiple') ?? false
      },
    }
    const choices = interaction.options.getString('choices');
    if (choices) {
      const answers = choices.split(',');
      message.poll.answers = [];
      for (let i = 0; i < answers.length; i++) {
        message.poll.answers.push({ text: answers[i].trim(), emoji: emojiCharacters[i + 1] });
      }
    } else {
      message.poll.answers = [{ text: 'Yes', emoji: `👍` }, { text: 'No', emoji: `👎`}];
    }
    console.log(message);
    await interaction.followUp({ content: `Poll started by ${interaction.user.id}`, poll: message.poll })
  }
}

Versions

  • discord.js 14.15.1
  • Node.js 20.10.0

Issue priority

Low (slightly annoying)

Which partials do you have configured?

No Partials

Which gateway intents are you subscribing to?

Guilds, GuildMembers, GuildVoiceStates, GuildMessages, MessageContent, GuildMessagePolls

I have tested this issue on a development release

No response

@Jiralite
Copy link
Member

Jiralite commented May 6, 2024

You cannot edit a message with a poll.

@Jiralite Jiralite closed this as not planned Won't fix, can't repro, duplicate, stale May 6, 2024
@IslandRhythms
Copy link
Author

Is a slash command editing a message? If so it should mentioned somewhere in the docs this is the case.

@Jiralite
Copy link
Member

Jiralite commented May 6, 2024

Is a slash command editing a message?

The slash command you provided is indeed editing a message. Think about what you are doing:

  1. You used interaction.deferReply();. This created a message in a channel.
  2. You edit that message via interaction.followUp().

If so it should mentioned somewhere in the docs this is the case.

Perhaps you should read the guide. Specifically, this page:

Note that if you use followUp() after a deferReply(), the first follow-up will edit the <application> is thinking message rather than sending a new one.

@IslandRhythms
Copy link
Author

So are you saying if I don't defer the reply it'll work? The function reply() indicates to me a message is not being editted?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants