我正在發出帶有確認資訊的禁止命令。我為此使用了按鈕和 MessageComponentCollector。但是它失敗并輸出錯誤。這是我的代碼:
var bu1tton = new Discord.MessageButton()
.setStyle(`SUCCESS`)
.setEmoji(`872905464797605938`)
.setLabel(`Proceed`)
.setCustomId("proceed")
var bt1 = new Discord.MessageButton()
.setStyle("DANGER")
.setEmoji(`872905464747286598`)
.setLabel(`Cancel`)
.setCustomId("back")
var row = new Discord.MessageActionRow()
.addComponents([bu1tton, bt1])
const confirmation = interaction.followUp({
embeds: [new Discord.MessageEmbed().setTitle(`Are you sure?`).setColor("RED").setDescription(`Are you sure you want to ban **${target.user.tag}** for ${reason}?\nThis action will be automatically canceled in 10 seconds if you do not select any option.`).setFooter(interaction.guild.name)],
components: [row]
})
const filter = ( inter ) => inter.user.id === interaction.user.id
const collector = confirmation.createMessageComponentCollector({ filter, time: 10000 })
collector.on('collect', async interaction => {
if(interaction.customId === "proceed") {
interaction.deferReply()
await interaction.followUp({
content: `**${interaction.user.tag}** banned **${target.user.tag}**.\nReason: *${reason}*.`
})
const reportChannel = interaction.guild.channels.cache.get(log_channel)
const messageLink = `https://discord.com/channels/${interaction.guild.id}/${interaction.channel.id}/${interaction.id}`;
let logchat = new Discord.MessageEmbed()
.setAuthor(`${interaction.user.tag} (${interaction.user.id})`, interaction.user.displayAvatarURL())
.setDescription(`**<:target:890913045126213633> Member:** ${target.user} (${target.user.id})\n**<:law:913487126576914502> Action:** Ban\n**<:decision:890913045537235005> Reason:** ${reason}\n**<:link:907511618097803284> Link:** [Click here](${messageLink})`)
.setColor('RED')
.setFooter(`ID: ${uuidv4()}`)
.setTimestamp();
const log = await reportChannel.send({
embeds: [logchat]
})
const data = log.embeds[0]
let dmembed = new Discord.MessageEmbed()
.setTitle("You have been banned from Rice Farm #11")
.setDescription(`If you find this ban abusive or wrong, please proceed to [Ban Appeal page](https://ricesupport.brizy.site/).`)
.addField("Moderator", `${interaction.user}`)
.addField("Reason", `${reason}`)
.setColor("RED")
.setFooter(`${data.footer.text}`)
.setTimestamp();
await target.send({
embeds: [dmembed]
}).catch((err) => console.log(err));
await target.ban({
reason: `Banned by ${interaction.user.tag} | Reason: ${reason}`,
days: num
}).catch((err) => console.log(err));
}
if(interaction.customId === "back") {
interaction.deferReply()
interaction.message.delete()
}
})
collector.on('end', async interaction => {
})
它發送帶有組件的嵌入,但收集器顯然不會創建。
這是完整的錯誤:
[Error Handling System] Unhandled Rejection/Catch
TypeError: confirmation.createMessageComponentCollector is not a function
at Object.run (/PC/184395345943/slash/Moderation/ban.js:114:36) Promise {
<rejected> TypeError: confirmation.createMessageComponentCollector is not a function
at Object.run (/PC/184395345943/slash/Moderation/ban.js:114:36)
}
我嘗試將confirmation.createMessageComponentCollector(...)line更改為confirmation.message.createMessageComponentCollector(...),但它輸出幾乎相同的錯誤:
confirmation.message.createMessageComponentCollector() - undefined
這讓我很困惑。先感謝您!<3
uj5u.com熱心網友回復:
followUp回傳 a Promise <(Message|APIMessage )>,例如參見此檔案。所以你需要await對它:
const confirmation = await interaction.followUp({
...
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/383568.html
標籤:javascript 节点.js 不和谐 不和谐.js 机器人
