#Help with buttons
1 messages · Page 1 of 1 (latest)
oh ok
module.exports.run = (client, message, args) => {
client.on('interactionCreate', async interaction => {
const row = new MessageActionRow()
.addComponents(
new MessageButton()
.setCustomId('Attack')
.setEmoji(':crossed_swords:')
.setLabel('Attack')
.setStyle('SUCCESS')
)
.addComponents(
new MessageButton()
.setCustomId('Items')
.setEmoji(':pouch:')
.setLabel('Items')
.setStyle('PRIMARY')
)
.addComponents(
new MessageButton()
.setCustomId('Flee')
.setEmoji(':dash:')
.setLabel('Flee')
.setStyle('DANGER')
)
await interaction.reply({
content: 'Choose your action:',
components: [row],
ephemeral: true,
});
const filter = i => i.customId === 'primary';
const collector = interaction.channel.createMessageComponentCollector({
filter,
max: 1,
time: 1000 * 60, //60 seconds to confirm choice
});
collector.on('collect', async i => {
if (i.customId === 'primary') {
await i.update({ content: 'A button was clicked!', components: [] });
}
});
collection.forEach((click) => {
console.log(click.user.id, click.customId)
})
if (collection.first()?.customId === 'Attack') {
//attack opponent
interaction.channel?.send({
content: 'You attacked',
})
}
else if (collection.first()?.customId === 'Items') {
//open items
interaction.channel?.send({
content: 'You opened your bag',
})
}
else if (collection.first()?.customId === 'Flee') {
//flee
interaction.channel?.send({
content: 'You fled',
})
}
else {
//continue waiting for input???
console.log('Unknown action performed')
}
await interaction.editReply({
content:'Your action:',
components: []
})
});
});
}```
I posted this like that and I got muted immediately
xd
also here is the full uncut error in all its nasty glory if you wanted to see
const collector = interaction.channel.createMessageComponentCollector({
^
ReferenceError: interaction is not defined
at Object.module.exports.run (D:\Coding Assignments\CS370\Discord Bot+PersonalCommandHandler\commands\combatButtons.js:38:23)
at Client.<anonymous> (D:\Coding Assignments\CS370\Discord Bot+PersonalCommandHandler\index.js:39:17)
at Client.emit (node:events:520:28)
at MessageCreateAction.handle (D:\Coding Assignments\CS370\Discord Bot+PersonalCommandHandler\node_modules\discord.js\src\client\actions\MessageCreate.js:26:14)
at Object.module.exports [as MESSAGE_CREATE] (D:\Coding Assignments\CS370\Discord Bot+PersonalCommandHandler\node_modules\discord.js\src\client\websocket\handlers\MESSAGE_CREATE.js:4:32)
at WebSocketManager.handlePacket (D:\Coding Assignments\CS370\Discord Bot+PersonalCommandHandler\node_modules\discord.js\src\client\websocket\WebSocketManager.js:351:31)
at WebSocketShard.onPacket (D:\Coding Assignments\CS370\Discord Bot+PersonalCommandHandler\node_modules\discord.js\src\client\websocket\WebSocketShard.js:444:22)
at WebSocketShard.onMessage (D:\Coding Assignments\CS370\Discord Bot+PersonalCommandHandler\node_modules\discord.js\src\client\websocket\WebSocketShard.js:301:10)
at WebSocket.onMessage (D:\Coding Assignments\CS370\Discord Bot+PersonalCommandHandler\node_modules\ws\lib\event-target.js:199:18)
at WebSocket.emit (node:events:520:28)
[nodemon] app crashed - waiting for file changes before starting...```
hm it should work
im going crazy trying to find out whats wrong with it
if u can do ts await interaction.reply({ content: 'Choose your action:', components: [row], ephemeral: true, }); then interaction is defined
lol
lol
but its not creating any output
oh.