繁体   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