我是一个不和谐的机器人使用按钮,一切运行良好,没有错误,但我被困在点,当我点击按钮,什么都没有发生。由于Discord.js在最近的更新中做了一些更改,所以我无法找到合适的解决方案。下面是密码-
const { MessageActionRow, MessageButton, MessageEmbed } = require("discord.js")
module.exports ={
name:'ping',
execute(message, arg){
const row = new MessageActionRow()
.addComponents(
new MessageButton()
.setCustomId('id1')
.setLabel('LoL')
.setStyle('DANGER')
)
const ping = new MessageEmbed()
.setDescription('First Button event!')
.setTimestamp()
.setImage('https://images2.alphacoders.com/927/thumbbig-927608.webp')
.setColor('RANDOM')
const lol = new MessageActionRow()
.addComponents(
new MessageButton()
.setStyle('LINK')
.setLabel('Link to Image!')
.setURL('https://images2.alphacoders.com/927/thumbbig-927608.webp')
)
message.channel.send({content :'Hello! This is my first Button event by using command handeler!! ',embeds:[ping], components :[row , lol]})
}
}
下面是主文件的代码
client.on('message', message => {
if(!message.content.startsWith(PREFIX)|| message.author.bot) return
const arg = message.content.slice(PREFIX.length).split(/ +/)
const command = arg.shift().toLowerCase()
if (command === 'ping'){
client.commands.get('ping').execute(message, arg)
}
})
client.on('clickButton', async (button) =>{
} )
发布于 2022-02-23 23:33:12
没有clickButton
事件。处理任何交互(包括单击按钮)的事件是interactionCreate
。在那里,您将检查交互是否是一个按钮(因为它也可以是斜杠命令、选择菜单、上下文菜单、模态等等)。然后用它做你想做的。也许在使用之前也要检查按钮的ID。
client.on('interactionCreate', interaction => {
if (!interaction.isButton()) return;
if (interaction.customId == "id1") {
// Do what you want with button 'id1'.
}
});
如果您想知道可以在interaction
上使用的方法和属性,则按钮交互的文档是这里。
https://stackoverflow.com/questions/71245194
复制相似问题