我如何使bot对自己的消息做出反应并编辑先前发送的嵌入?



我在discord.js中创建了一个不和谐bot,问题在这里:当我反应对于消息,机器人给了我一个错误…也许是因为我试过多种密码……(请同时阅读评论)

TypeError: Function.prototype.apply被调用#<对象>,它是对象而不是函数

module.exports = { 
name: 'emoji',
group: 'misc',
aliases: ['emoticon'],
description: 'mostra ajuda.', 
use:'.help <comando>',
async execute(message,args){

try{
const filter = (reaction, user) => reaction.emoji.name === '▶️' && user.id === message.author.id;
let newEmbed = new Discord.MessageEmbed() //I was using this to test the part where the bot edited the embed but I just ended up deleting that to see where the error was coming from.
.setDescription('a')

let ajuda = new Discord.MessageEmbed()
.setColor('#0099ff')
.setAuthor(`Comando por ${message.author.username}`, message.author.displayAvatarURL({dynamic: true}),message.url)
.setTitle(`**Ajuda**`) 
.setDescription('**Modo de uso:** .help <comando> n _Exemplo: .help config_')
.addFields(
{name: '**configuração**', value: 'mostra comandos de.'},
)
.setTimestamp()
.setFooter('[PRD] Corridas todos os direitos reservados.')
await message.channel.send({embed: ajuda})
.then(function (message) {
message.react("▶️")
message.awaitReactions({ filter, max: 1, time: 60000, errors: ['time'] })
.then(collected => {
const collect = collected.first();
if(emojis.first(collect.emoji) === '▶️') {
message.reply('code worked')// HERE SHOULD GO THE CODE TO EDIT THE EMBED INSTEAD.  
}
})
.catch(err => { 
console.log(err)
})
}).catch(function(){   
})      
}
catch(error){
console.log(error)
}
}
}

我已经测试了你的代码,并提出了一个解决方案。

当你调用反应收集器时,你做:

message.awaitReactions({ filter, max: 1, time: 60000, errors: ['time'] })

filter是你的过滤器函数,但是我确定过滤器函数应该是函数的第一个参数,其余的选项是第二个参数,因此这行应该看起来像这样:

message.awaitReactions(filter, { max: 1, time: 60000, errors: ["time"] })

你有代码来编辑嵌入的权利

你最终的代码应该看起来像这样:
我对代码的格式做了一些改动,在
module.exports = {
name: "emoji",
group: "misc",
aliases: ["emoticon"],
description: "mostra ajuda.",
use: ".help <comando>",
async execute(message, args) {
try {
const filter = (reaction, user) =>
reaction.emoji.name === "▶️" && user.id === message.author.id;
let ajuda = new Discord.MessageEmbed()
.setColor("#0099ff")
.setAuthor(
`Comando por ${message.author.username}`,
message.author.displayAvatarURL({ dynamic: true }),
message.url
)
.setTitle(`**Ajuda**`)
.setDescription(
"**Modo de uso:** .help <comando> n _Exemplo: .help config_"
)
.addFields({
name: "**config**",
value: "shows config commands",
})
.setTimestamp()
.setFooter("[PRD] Corridas todos os direitos reservados.");
await message.channel
.send({ embed: ajuda })
.then(function (message) {
message.react("▶️");
message
.awaitReactions(filter, {
max: 1,
time: 60000,
errors: ["time"],
})
// When a reaction is collected
.then((collected) => {
let newEmbed =
new Discord.MessageEmbed().setDescription("a");
// Edit the embed
message.edit(newEmbed);
})
.catch((err) => {
console.log(err);
});
})
.catch(function () {
//Something
});
} catch (error) {
console.log(error);
}
},
};

const filter = (reaction, user) => reaction.emoji.name === "▶️" && user.id === message.author.id;
const ajuda = new Discord.MessageEmbed()
.setColor('#0099ff')
.setDescription('...');
const sentEmbed = await message.channel.send({ embed: ajuda });
await sentEmbed.react("▶️");

const emojiCollector = await msg.createReactionCollector(Filter, {
time: 60000,
max: 1 //can be ignored for unlimited amount of event-firing.
});
emojiCollector.on("collect", async (r) => {
if (r.emoji.name === "▶️") {
console.log("If statement fired.");
//do something
}
});

最新更新