簡體   English   中英

我如何讓機器人在不帶“\\_poll”的情況下使用 discord.js 發送輪詢消息的 adv poll 命令

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

如果沒有“_poll”,我似乎無法讓機器人發送投票消息。 我錯過了什么?

下面的代碼示例:

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不會改變它正在替換的字符串的值,它只是返回一個新字符串。

因此,為了從您的消息內容中刪除_poll ,請創建一個新變量並將該變量設置為替換文本。 下面是一個例子:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM