我似乎无法让机器人在没有“_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('👎');
});
};
关于javascript - 如何让机器人使用discord.js 发送没有 '\_poll' 的 adv poll 命令的投票消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64299148/