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

I can't seem to get the bot to send the message of the poll without the '_poll'.如果没有“_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. replace不会改变它正在替换的字符串的值,它只是返回一个新字符串。

So in order to remove _poll from your message content, create a new variable and set that variable to the replaced text.因此,为了从您的消息内容中删除_poll ,请创建一个新变量并将该变量设置为替换文本。 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('👎');
 });
};

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何制作提前投票命令 Discord.js - How To Make An Advance Poll Command Discord.js 所以我创建了一个不和谐的投票机器人。 我如何使它如此特定的角色可以使用机器人? (discord.js) - So i have created a discord poll bot. How do i make it so specific role can use the bot? (discord.js) Discord.js结果轮询命令需要一些工作 - Discord.js result poll command that needs some work 如何允许成员只对投票 discord.js 做出反应 - How to allow a member to only react once to the poll discord.js 在Discord.JS中遇到Poll命令问题。 你是如何解决这个问题的? - Having problems with Poll Command in Discord.JS. How do you fix this? Discord.JS 无法识别投票中的第一个选项 - Discord.JS Won't Recognize the first option in a Poll 我的 poll 命令在 discord.js v12 中不起作用 - My poll command isn't working in discord.js v12 Discord.js 如何让机器人对它刚刚通过 id 在 discord 中发送的消息做出反应? - Discord.js How do I get the bot to react to the message it just sent in discord by id? 如何在没有消息的情况下向特定频道发送消息 object Discord.js - How do I send a message to a specific channel without a message object Discord.js 我正在尝试为我的 discord 机器人发出轮询命令,但它一直给我错误:“TypeError: Cannot read property 'push' of undefined” - I'm trying to make a poll command for my discord bot, but it keeps giving me the error: “TypeError: Cannot read property 'push' of undefined”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM