Comparing version 1.0.18 to 1.0.19
58
index.js
const fs = require('fs'); | ||
const readlineSync = require('readline-sync'); | ||
const { Client, Intents } = require('discord.js'); | ||
const { Client, Intents, MessageActionRow, MessageButton } = require('discord.js'); | ||
const commandStates = { | ||
ping: false, | ||
}; | ||
function getToken() { | ||
@@ -30,11 +34,47 @@ try { | ||
client.once('ready', () => { | ||
console.log(`Logged in as ${client.user.tag}!`); | ||
startBot(); // Start bot after client is ready | ||
}); | ||
client.on('messageCreate', async message => { | ||
if (message.content.startsWith('!ping')) { | ||
await message.reply('Pong!'); | ||
console.log(`Logged in as ${client.user.tag}!`); | ||
}); | ||
client.on('messageCreate', async message => { | ||
if (message.content === '!commands') { | ||
const row = new MessageActionRow(); | ||
for (const command in commandStates) { | ||
const button = new MessageButton() | ||
.setCustomId(command) | ||
.setLabel(command) | ||
.setStyle(commandStates[command] ? 'SUCCESS' : 'SECONDARY'); | ||
row.addComponents(button); | ||
} | ||
await message.channel.send({ content: 'Choose a command:', components: [row] }); | ||
} | ||
}); | ||
client.on('interactionCreate', async interaction => { | ||
if (!interaction.isButton()) return; | ||
const { customId } = interaction; | ||
commandStates[customId] = !commandStates[customId]; | ||
const newStyle = commandStates[customId] ? 'SUCCESS' : 'SECONDARY'; | ||
const newButton = interaction.message.components[0].components.find(button => button.customId === customId); | ||
newButton.setStyle(newStyle); | ||
await interaction.update({ components: [interaction.message.components[0]] }); | ||
if (commandStates[customId]) { | ||
await executeCommand(customId, interaction); | ||
} | ||
}); | ||
async function executeCommand(command, interaction) { | ||
switch (command) { | ||
case 'ping': | ||
await interaction.reply('Pong!'); | ||
break; | ||
default: | ||
break; | ||
} | ||
} | ||
}); | ||
@@ -41,0 +81,0 @@ function startBot() { |
{ | ||
"name": "vs-bot", | ||
"version": "1.0.18", | ||
"version": "1.0.19", | ||
"description": "free bot's", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
3890
108