How do I get a bot to send the message of the poll without the '\_poll' for an adv poll command with discord.js

Viewed 82

I can't seem to get the bot to send the message of the poll without the '_poll'. What am I missing?

Code sample below:

module.exports = (client) => {
 const command = require('./command');

 command(client, 'poll', async (message) => {
  const tag = `<@${message.author.id}>`;

  message.content.replace('_poll', ' ');
  const sentMessage = await message.channel.send(
   `${tag} started a poll: **${message.content}**`
  );

  sentMessage.react('');
  sentMessage.react('');
 });
};
1 Answers

replace does not change the value of the string it is replacing, it simply returns a new string.

So in order to remove _poll from your message content, create a new variable and set that variable to the replaced text. Here is an example:

module.exports = (client) => {
 const command = require('./command');

 command(client, 'poll', async (message) => {
  const tag = `<@${message.author.id}>`;

  var content = message.content.replace('_poll', ' '); //Added a variable here

  const sentMessage = await message.channel.send(
   `${tag} started a poll: **${content}**`
  );

  sentMessage.react('');
  sentMessage.react('');
 });
};
Related