我是JavaScript编码的新手,因此,如果您可以将其作为一个简单的简单解释,将不胜感激。
因此,基本上,我已经制作了这个小脚本,以便使用我让用户输入的参数将民意调查发送到另一个频道,然后对其进行格式化并将其作为嵌入式消息发送
脚本正在发送格式化的全部内容,但是不添加反应的最后一步就是问题。 (它们是我已经定义的自定义反应,您将在下面看到)
if (args.length >= 1) {
message.delete().then(() => {
const pollEmbed = new Discord.RichEmbed()
.setColor('#ABDFF2')
.setTitle("** " + pollArgs[0] + " **")
.setDescription(pollArgs[1])
.addField('*Click on the reactions below to cast your opinion on this poll!*', 'If you would like to start your own poll: !help in <#726235250136580106>')
.setTimestamp()
.setThumbnail(message.author.displayAvatarURL)
.setFooter(message.author.tag + " | Peace Keeper", message.author.displayAvatarURL)
let yes = message.guild.emojis.find('name', "yes")
let no = message.guild.emojis.find('name', "no")
suggestionschannel.send(pollEmbed).then(message.react(yes, no));
如果您需要在此处查看完整的代码,则为:
const Discord = require("discord.js");
const client = new Discord.Client();
module.exports.run = async (bot, message, args) => {
const suggestionschannel = message.guild.channels.find("name", "suggestions");
let pollArgs = args.slice(0).join(" ").split('|');
if (args.length >= 1) {
message.delete().then(() => {
const pollEmbed = new Discord.RichEmbed()
.setColor('#ABDFF2')
.setTitle("** " + pollArgs[0] + " **")
.setDescription(pollArgs[1])
.addField('*Click on the reactions below to cast your opinion on this poll!*', 'If you would like to start your own poll: !help in <#726235250136580106>')
.setTimestamp()
.setThumbnail(message.author.displayAvatarURL)
.setFooter(message.author.tag + " | Peace Keeper", message.author.displayAvatarURL)
let yes = message.guild.emojis.find('name', "yes")
let no = message.guild.emojis.find('name', "no")
suggestionschannel.send(pollEmbed).then(message.react(yes, no));
})
} else {
message.delete().catch();
const pollErrEmbed = new Discord.RichEmbed()
.setColor('FF6961')
.setTitle("**error!**")
.addField("use the correct format: !polls-start <title> | <message>", "If you need help do: `!polls-help`.")
.setTimestamp()
.setFooter(message.author.tag + " | Peace Keeper", message.author.displayAvatarURL)
message.reply(pollErrEmbed).then(msg => msg.delete(10000));
}
}
module.exports.help = {
name: "polls-start"
}
答案 0 :(得分:0)
您的代码似乎只有一个小小的修改就好!
代替
suggestionschannel.send(pollEmbed).then(message.react(yes, no));
您需要使用
suggestionschannel.send(pollEmbed).then(message => {
message.react(yes);
message.react(no);
});
还记得Updating Discord.js to v12,因为对v11的支持即将终止!