简体   繁体   中英

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

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('👎');
 });
};

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('👎');
 });
};

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM