GustyCube
GustyCube
DIAdiscord.js - Imagine an app
Created by GustyCube on 8/4/2024 in #djs-questions
Emojies not working with select
const { ActionRowBuilder, StringSelectMenuBuilder, StringSelectMenuInteraction, InteractionType } = require('discord.js');
const config = require('../../../ticketConfig.json');

module.exports = async (client, interaction) => {

console.log("Interaction received:", interaction);

if (interaction.type !== InteractionType.MessageComponent) {
console.log("Interaction is not of type MessageComponent.");
return;
}

if (!(interaction instanceof StringSelectMenuInteraction)) {
console.log("Interaction is not an instance of StringSelectMenuInteraction.");
return;
}

if (!interaction.customId.startsWith('select_category_')) {
console.log("customId does not start with 'select_category_'.");
return;
}

const selectedCategory = config.categories.find(category => category.name.toLowerCase() === interaction.values[0]);
if (!selectedCategory) {
console.log("Selected category not found.");
return;
}

const categoryEmoji = selectedCategory.emoji
? parseEmoji(selectedCategory.emoji)
: undefined;

const items = selectedCategory.items.map(item => {
return {
label: item.name,
value: item.id
};
});

console.log("Mapped items:", items);
console.log("Category emoji:", categoryEmoji);

try {
const itemMenu = new StringSelectMenuBuilder()
.setCustomId(`select_item_${selectedCategory.name.toLowerCase()}`)
.setPlaceholder('Select an item')
.addOptions(items);

const row = new ActionRowBuilder().addComponents(itemMenu);

await interaction.update({
content: `Please select an item from **${selectedCategory.name}** ${categoryEmoji ? `<:${categoryEmoji.name}:${categoryEmoji.id}>` : ''}:`,
components: [row],
ephemeral: true
});
} catch (err) {
console.log("Error during menu creation or interaction update:", err);
}
};

function parseEmoji(emojiString) {
const [name, id] = emojiString.split(':');
return { name, id };
}
const { ActionRowBuilder, StringSelectMenuBuilder, StringSelectMenuInteraction, InteractionType } = require('discord.js');
const config = require('../../../ticketConfig.json');

module.exports = async (client, interaction) => {

console.log("Interaction received:", interaction);

if (interaction.type !== InteractionType.MessageComponent) {
console.log("Interaction is not of type MessageComponent.");
return;
}

if (!(interaction instanceof StringSelectMenuInteraction)) {
console.log("Interaction is not an instance of StringSelectMenuInteraction.");
return;
}

if (!interaction.customId.startsWith('select_category_')) {
console.log("customId does not start with 'select_category_'.");
return;
}

const selectedCategory = config.categories.find(category => category.name.toLowerCase() === interaction.values[0]);
if (!selectedCategory) {
console.log("Selected category not found.");
return;
}

const categoryEmoji = selectedCategory.emoji
? parseEmoji(selectedCategory.emoji)
: undefined;

const items = selectedCategory.items.map(item => {
return {
label: item.name,
value: item.id
};
});

console.log("Mapped items:", items);
console.log("Category emoji:", categoryEmoji);

try {
const itemMenu = new StringSelectMenuBuilder()
.setCustomId(`select_item_${selectedCategory.name.toLowerCase()}`)
.setPlaceholder('Select an item')
.addOptions(items);

const row = new ActionRowBuilder().addComponents(itemMenu);

await interaction.update({
content: `Please select an item from **${selectedCategory.name}** ${categoryEmoji ? `<:${categoryEmoji.name}:${categoryEmoji.id}>` : ''}:`,
components: [row],
ephemeral: true
});
} catch (err) {
console.log("Error during menu creation or interaction update:", err);
}
};

function parseEmoji(emojiString) {
const [name, id] = emojiString.split(':');
return { name, id };
}
9 replies
DIAdiscord.js - Imagine an app
Created by GustyCube on 7/28/2024 in #djs-questions
Interaction returning undefined
Any idea why my interaction is returning undefined? I can't check if its a select because it is just returning Client:
const { ActionRowBuilder, StringSelectMenuBuilder, StringSelectMenuInteraction, InteractionType, Client, GatewayIntentBits } = require('discord.js');
const config = require('../../../ticketConfig.json');


module.exports = async (interaction) => {
console.log("Interaction received:", interaction);
console.log("Interaction type:", interaction.type);

if (interaction.type !== InteractionType.MessageComponent) {
console.log("Interaction is not a MessageComponent, it's:", interaction.type);
return;
}

if (!(interaction instanceof StringSelectMenuInteraction)) {
console.log("Interaction is not a StringSelectMenuInteraction");
return;
}

if (!interaction.customId.startsWith('select_category_')) {
console.log("Interaction customId does not start with 'select_category_'");
return;
}

console.log("It's a StringSelectMenuInteraction with the correct customId");

const selectedCategory = config.categories.find(category => category.name.toLowerCase() === interaction.values[0]);
if (!selectedCategory) {
console.log("Selected category not found in config");
return;
}

console.log("Selected category found:", selectedCategory.name);

const items = selectedCategory.items.map(item => ({
label: item.name,
value: item.id
}));

const itemMenu = new StringSelectMenuBuilder()
.setCustomId(`select_item_${selectedCategory.name.toLowerCase()}`)
.setPlaceholder('Select an item')
.addOptions(items);

const row = new ActionRowBuilder().addComponents(itemMenu);

await interaction.update({ content: 'Please select an item:', components: [row], ephemeral: true });
};
const { ActionRowBuilder, StringSelectMenuBuilder, StringSelectMenuInteraction, InteractionType, Client, GatewayIntentBits } = require('discord.js');
const config = require('../../../ticketConfig.json');


module.exports = async (interaction) => {
console.log("Interaction received:", interaction);
console.log("Interaction type:", interaction.type);

if (interaction.type !== InteractionType.MessageComponent) {
console.log("Interaction is not a MessageComponent, it's:", interaction.type);
return;
}

if (!(interaction instanceof StringSelectMenuInteraction)) {
console.log("Interaction is not a StringSelectMenuInteraction");
return;
}

if (!interaction.customId.startsWith('select_category_')) {
console.log("Interaction customId does not start with 'select_category_'");
return;
}

console.log("It's a StringSelectMenuInteraction with the correct customId");

const selectedCategory = config.categories.find(category => category.name.toLowerCase() === interaction.values[0]);
if (!selectedCategory) {
console.log("Selected category not found in config");
return;
}

console.log("Selected category found:", selectedCategory.name);

const items = selectedCategory.items.map(item => ({
label: item.name,
value: item.id
}));

const itemMenu = new StringSelectMenuBuilder()
.setCustomId(`select_item_${selectedCategory.name.toLowerCase()}`)
.setPlaceholder('Select an item')
.addOptions(items);

const row = new ActionRowBuilder().addComponents(itemMenu);

await interaction.update({ content: 'Please select an item:', components: [row], ephemeral: true });
};
2 replies
DIAdiscord.js - Imagine an app
Created by GustyCube on 7/6/2024 in #djs-questions
bot just crashes
const { Client, Interaction, ApplicationCommandOptionType, PermissionFlagsBits } = require('discord.js');
const fs = require('fs');
const path = require('path');

// Define the path to the data file three directories up from the current directory
const dataFilePath = path.join(__dirname, '../../../data.json');

module.exports = {
name: 'add',
description: 'Set the stock',
options: [
{
name: 'account-type',
description: 'The type of account',
type: ApplicationCommandOptionType.Channel,
required: true,
},
{
name: 'state',
description: 'The state of the account',
type: ApplicationCommandOptionType.String,
required: true,
choices: [
{
name: 'resting',
value: 'resting',
},
{
name: 'stock',
value: 'stock',
},
],
},
{
name: 'amount',
description: 'The amount of accounts',
type: ApplicationCommandOptionType.Number,
required: true,
},
],
callback: async (client, interaction) => {
console.log('Callback function triggered');
try {
// Read the JSON data from the file
console.log(`Reading data from file: ${dataFilePath}`);
const data = JSON.parse(await fs.promises.readFile(dataFilePath, 'utf8'));
console.log('Data read successfully:', data);

// Extract options
const channelId = interaction.options.getChannel('account-type').id;
const state = interaction.options.getString('state');
const amount = interaction.options.getNumber('amount');

// Log the extracted options
console.log(`Extracted options - Channel ID: ${channelId}, State: ${state}, Amount: ${amount}`);

// Find the channel in the data
const channelData = data.channels.find(channel => channel.channelID === channelId);

if (!channelData) {
console.log(`Channel with ID ${channelId} not found.`);
return interaction.reply({ content: `Channel with ID ${channelId} not found.`, ephemeral: true });
}

// Update the state with the new amount
if (channelData.categories[state] !== undefined) {
console.log(`Current amount for ${state} before update: ${channelData.categories[state].amount}`);
oldamount = channelData.categories[state].amount
channelData.categories[state].amount += amount;
console.log(`Updated amount for ${state}: ${amount}`);

// Save the updated data back to the JSON file
await fs.promises.writeFile(dataFilePath, JSON.stringify(data, null, 2));
console.log('Data successfully written to file.');

return interaction.reply({ content: `Successfully updated ${state} amount to ${amount} for channel ID ${channelId}.`, ephemeral: true });
} else {
console.log(`State ${state} is not valid.`);
return interaction.reply({ content: `State ${state} is not valid.`, ephemeral: true });
}
} catch (err) {
console.error('Error processing the request:', err);
return interaction.reply({ content: 'An error occurred while updating the data.', ephemeral: true });
}
},
};
const { Client, Interaction, ApplicationCommandOptionType, PermissionFlagsBits } = require('discord.js');
const fs = require('fs');
const path = require('path');

// Define the path to the data file three directories up from the current directory
const dataFilePath = path.join(__dirname, '../../../data.json');

module.exports = {
name: 'add',
description: 'Set the stock',
options: [
{
name: 'account-type',
description: 'The type of account',
type: ApplicationCommandOptionType.Channel,
required: true,
},
{
name: 'state',
description: 'The state of the account',
type: ApplicationCommandOptionType.String,
required: true,
choices: [
{
name: 'resting',
value: 'resting',
},
{
name: 'stock',
value: 'stock',
},
],
},
{
name: 'amount',
description: 'The amount of accounts',
type: ApplicationCommandOptionType.Number,
required: true,
},
],
callback: async (client, interaction) => {
console.log('Callback function triggered');
try {
// Read the JSON data from the file
console.log(`Reading data from file: ${dataFilePath}`);
const data = JSON.parse(await fs.promises.readFile(dataFilePath, 'utf8'));
console.log('Data read successfully:', data);

// Extract options
const channelId = interaction.options.getChannel('account-type').id;
const state = interaction.options.getString('state');
const amount = interaction.options.getNumber('amount');

// Log the extracted options
console.log(`Extracted options - Channel ID: ${channelId}, State: ${state}, Amount: ${amount}`);

// Find the channel in the data
const channelData = data.channels.find(channel => channel.channelID === channelId);

if (!channelData) {
console.log(`Channel with ID ${channelId} not found.`);
return interaction.reply({ content: `Channel with ID ${channelId} not found.`, ephemeral: true });
}

// Update the state with the new amount
if (channelData.categories[state] !== undefined) {
console.log(`Current amount for ${state} before update: ${channelData.categories[state].amount}`);
oldamount = channelData.categories[state].amount
channelData.categories[state].amount += amount;
console.log(`Updated amount for ${state}: ${amount}`);

// Save the updated data back to the JSON file
await fs.promises.writeFile(dataFilePath, JSON.stringify(data, null, 2));
console.log('Data successfully written to file.');

return interaction.reply({ content: `Successfully updated ${state} amount to ${amount} for channel ID ${channelId}.`, ephemeral: true });
} else {
console.log(`State ${state} is not valid.`);
return interaction.reply({ content: `State ${state} is not valid.`, ephemeral: true });
}
} catch (err) {
console.error('Error processing the request:', err);
return interaction.reply({ content: 'An error occurred while updating the data.', ephemeral: true });
}
},
};
with this code my bot just crashes
3 replies
DIAdiscord.js - Imagine an app
Created by GustyCube on 7/4/2024 in #djs-questions
Bot stuck on thinking
here is my code:
const {
Client,
Interaction,
ApplicationCommandOptionType,
PermissionFlagsBits,
} = require('discord.js');
const fs = require('fs').promises;

module.exports = {
/**
*
* @param {Client} client
* @param {Interaction} interaction
*/
callback: async (client, interaction) => {
const channel = interaction.options.getChannel('channel');
const amount = interaction.options.getInteger('amount') || 0;
const channelId = channel.id;

await interaction.deferReply();

try {
// Read the existing data
const data = await fs.readFile('data.json', 'utf8');
const jsonData = JSON.parse(data);

// Add new channel entry
jsonData.channels.push({
channelID: channelId,
categories: {
resting: {
amount: 0
},
stock: {
amount: 0
}
}
});

// Write updated data back to file
await fs.writeFile('data.json', JSON.stringify(jsonData, null, 2));

await interaction.editReply(`New channel with ID ${channelId} created with stock amount set to ${amount}.`);
} catch (err) {
console.error('Error processing data file:', err);
await interaction.editReply('There was an error processing the data file.');
}
},

name: 'create',
description: 'Set the stock',
options: [
{
name: 'channel',
description: 'The channel to create or update.',
type: ApplicationCommandOptionType.Channel,
required: true,
},
],
permissionsRequired: [PermissionFlagsBits.ManageChannels],
};
const {
Client,
Interaction,
ApplicationCommandOptionType,
PermissionFlagsBits,
} = require('discord.js');
const fs = require('fs').promises;

module.exports = {
/**
*
* @param {Client} client
* @param {Interaction} interaction
*/
callback: async (client, interaction) => {
const channel = interaction.options.getChannel('channel');
const amount = interaction.options.getInteger('amount') || 0;
const channelId = channel.id;

await interaction.deferReply();

try {
// Read the existing data
const data = await fs.readFile('data.json', 'utf8');
const jsonData = JSON.parse(data);

// Add new channel entry
jsonData.channels.push({
channelID: channelId,
categories: {
resting: {
amount: 0
},
stock: {
amount: 0
}
}
});

// Write updated data back to file
await fs.writeFile('data.json', JSON.stringify(jsonData, null, 2));

await interaction.editReply(`New channel with ID ${channelId} created with stock amount set to ${amount}.`);
} catch (err) {
console.error('Error processing data file:', err);
await interaction.editReply('There was an error processing the data file.');
}
},

name: 'create',
description: 'Set the stock',
options: [
{
name: 'channel',
description: 'The channel to create or update.',
type: ApplicationCommandOptionType.Channel,
required: true,
},
],
permissionsRequired: [PermissionFlagsBits.ManageChannels],
};
the bot is just stuck on thinking...
3 replies
DIAdiscord.js - Imagine an app
Created by GustyCube on 5/27/2024 in #djs-questions
Error with bot
Hey. I'm using the pterotacy; api: and I got this error:
AxiosError: Request failed with status code 422
at settle (C:\Users\Bennett\Downloads\GustyHostBot\GustyHostBot\node_modules\axios\dist\node\axios.cjs:1983:12)
at IncomingMessage.handleStreamEnd (C:\Users\Bennett\Downloads\GustyHostBot\GustyHostBot\node_modules\axios\dist\node\axios.cjs:3085:11)
at IncomingMessage.emit (node:events:531:35)
at endReadableNT (node:internal/streams/readable:1696:12)
at process.processTicksAndRejections (node:internal/process/task_queues:82:21)
at Axios.request (C:\Users\Bennett\Downloads\GustyHostBot\GustyHostBot\node_modules\axios\dist\node\axios.cjs:4224:41)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async Object.callback (C:\Users\Bennett\Downloads\GustyHostBot\GustyHostBot\src\commands\servers\createAccount.js:38:24)
at async module.exports (C:\Users\Bennett\Downloads\GustyHostBot\GustyHostBot\src\events\interactionCreate\handleCommands.js:62:5)
at async Client.<anonymous> (C:\Users\Bennett\Downloads\GustyHostBot\GustyHostBot\src\handlers\eventHandler.js:16:9) {
code: 'ERR_BAD_REQUEST',
AxiosError: Request failed with status code 422
at settle (C:\Users\Bennett\Downloads\GustyHostBot\GustyHostBot\node_modules\axios\dist\node\axios.cjs:1983:12)
at IncomingMessage.handleStreamEnd (C:\Users\Bennett\Downloads\GustyHostBot\GustyHostBot\node_modules\axios\dist\node\axios.cjs:3085:11)
at IncomingMessage.emit (node:events:531:35)
at endReadableNT (node:internal/streams/readable:1696:12)
at process.processTicksAndRejections (node:internal/process/task_queues:82:21)
at Axios.request (C:\Users\Bennett\Downloads\GustyHostBot\GustyHostBot\node_modules\axios\dist\node\axios.cjs:4224:41)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async Object.callback (C:\Users\Bennett\Downloads\GustyHostBot\GustyHostBot\src\commands\servers\createAccount.js:38:24)
at async module.exports (C:\Users\Bennett\Downloads\GustyHostBot\GustyHostBot\src\events\interactionCreate\handleCommands.js:62:5)
at async Client.<anonymous> (C:\Users\Bennett\Downloads\GustyHostBot\GustyHostBot\src\handlers\eventHandler.js:16:9) {
code: 'ERR_BAD_REQUEST',
with this code:
const { SlashCommandBuilder } = require('discord.js');
const mysql = require('mysql2/promise');
const axios = require('axios');

const pool = mysql.createPool({
host: '',
user: '',
password: '',
database: ''
});

const PTERO_API_URL = 'https://URL/api/application/users';
const PTERO_API_KEY = '';

module.exports = {
name: 'register',
description: 'Register a user for the server',

async callback(interaction) {
const discordId = interaction.user.id;
const username = "GustyCube";

try {
const [rows] = await pool.query('SELECT * FROM users WHERE discord_id = ?', [discordId]);

if (rows.length > 0) {
await interaction.reply(`User with Discord ID ${discordId} already exists!`);
return;
}

const password = Math.random().toString(36).slice(-8);

console.log(username

)
console.log(password)
const response = await axios.post(`${PTERO_API_URL}`, {
username: username,
email: `${username}@example.com`,
first_name: username,
last_name: 'DiscordUser',
password: password
}, {
headers: {
'Authorization': `Bearer ${PTERO_API_KEY}`,
'Content-Type': 'application/json',
'Accept': 'application/json'
}
});

const pterodactylUserId = response.data.object.id;
print(pterodactylUserId)

await pool.query('INSERT INTO users (discord_id, username, pterodactyl_id) VALUES (?, ?, ?)', [discordId, username, pterodactylUserId]);

await interaction.reply(`User ${username} created successfully! A temporary password has been generated. Please set a new password through the Pterodactyl panel for security reasons.`);
} catch (error) {
console.error(error);
if (error.response && error.response.status === 429) {
await interaction.reply('Rate limit reached. Please try again later.');
} else {
await interaction.reply('There was an error creating the user. Please try again later.');
}
}
},
};
const { SlashCommandBuilder } = require('discord.js');
const mysql = require('mysql2/promise');
const axios = require('axios');

const pool = mysql.createPool({
host: '',
user: '',
password: '',
database: ''
});

const PTERO_API_URL = 'https://URL/api/application/users';
const PTERO_API_KEY = '';

module.exports = {
name: 'register',
description: 'Register a user for the server',

async callback(interaction) {
const discordId = interaction.user.id;
const username = "GustyCube";

try {
const [rows] = await pool.query('SELECT * FROM users WHERE discord_id = ?', [discordId]);

if (rows.length > 0) {
await interaction.reply(`User with Discord ID ${discordId} already exists!`);
return;
}

const password = Math.random().toString(36).slice(-8);

console.log(username

)
console.log(password)
const response = await axios.post(`${PTERO_API_URL}`, {
username: username,
email: `${username}@example.com`,
first_name: username,
last_name: 'DiscordUser',
password: password
}, {
headers: {
'Authorization': `Bearer ${PTERO_API_KEY}`,
'Content-Type': 'application/json',
'Accept': 'application/json'
}
});

const pterodactylUserId = response.data.object.id;
print(pterodactylUserId)

await pool.query('INSERT INTO users (discord_id, username, pterodactyl_id) VALUES (?, ?, ?)', [discordId, username, pterodactylUserId]);

await interaction.reply(`User ${username} created successfully! A temporary password has been generated. Please set a new password through the Pterodactyl panel for security reasons.`);
} catch (error) {
console.error(error);
if (error.response && error.response.status === 429) {
await interaction.reply('Rate limit reached. Please try again later.');
} else {
await interaction.reply('There was an error creating the user. Please try again later.');
}
}
},
};
Their documentation: https://dashflo.net/docs/api/pterodactyl/v1/#req_802e27a56fe142c99db4106d8e8e8892 You go to API/Application > /users > POST create user
3 replies
DIAdiscord.js - Imagine an app
Created by GustyCube on 5/24/2024 in #djs-questions
Error with a command
Here is my code:
const { SlashCommandBuilder } = require('discord.js');
const mysql = require('mysql2/promise');
const axios = require('axios');

const pool = mysql.createPool({
host: 'your-database-host',
user: 'your-database-user',
password: 'your-database-password',
database: 'your-database-name'
});

const PTERO_API_URL = 'https://pterodactyl-instance.com/api/application';
const PTERO_API_KEY = 'pterodactyl-api-key';

module.exports = {
name: 'register',
description: 'Register a user for the server',

async execute(interaction) {
const discordId = interaction.user.id;
const username = interaction.user.username;

try {
const [rows] = await pool.query('SELECT * FROM users WHERE discord_id = ?', [discordId]);

if (rows.length > 0) {
await interaction.reply(`User with Discord ID ${discordId} already exists!`);
return;
}

const response = await axios.post(`${PTERO_API_URL}/users`, {
username: username,
email: `${username}@example.com`,
first_name: username,
last_name: 'DiscordUser',
password: 'some-secure-password'
}, {
headers: {
'Authorization': `Bearer ${PTERO_API_KEY}`,
'Content-Type': 'application/json',
'Accept': 'application/json'
}
});

const pterodactylUserId = response.data.attributes.id;

await pool.query('INSERT INTO users (discord_id, username, pterodactyl_id) VALUES (?, ?, ?)', [discordId, username, pterodactylUserId]);

await interaction.reply(`User ${username} created successfully!`);
} catch (error) {
console.error(error);
await interaction.reply('There was an error creating the user. Please try again later.');
}
},
};
const { SlashCommandBuilder } = require('discord.js');
const mysql = require('mysql2/promise');
const axios = require('axios');

const pool = mysql.createPool({
host: 'your-database-host',
user: 'your-database-user',
password: 'your-database-password',
database: 'your-database-name'
});

const PTERO_API_URL = 'https://pterodactyl-instance.com/api/application';
const PTERO_API_KEY = 'pterodactyl-api-key';

module.exports = {
name: 'register',
description: 'Register a user for the server',

async execute(interaction) {
const discordId = interaction.user.id;
const username = interaction.user.username;

try {
const [rows] = await pool.query('SELECT * FROM users WHERE discord_id = ?', [discordId]);

if (rows.length > 0) {
await interaction.reply(`User with Discord ID ${discordId} already exists!`);
return;
}

const response = await axios.post(`${PTERO_API_URL}/users`, {
username: username,
email: `${username}@example.com`,
first_name: username,
last_name: 'DiscordUser',
password: 'some-secure-password'
}, {
headers: {
'Authorization': `Bearer ${PTERO_API_KEY}`,
'Content-Type': 'application/json',
'Accept': 'application/json'
}
});

const pterodactylUserId = response.data.attributes.id;

await pool.query('INSERT INTO users (discord_id, username, pterodactyl_id) VALUES (?, ?, ?)', [discordId, username, pterodactylUserId]);

await interaction.reply(`User ${username} created successfully!`);
} catch (error) {
console.error(error);
await interaction.reply('There was an error creating the user. Please try again later.');
}
},
};
I get: There was an error running this command: TypeError: commandObject.callback is not a function. Why is that?
5 replies
DIAdiscord.js - Imagine an app
Created by GustyCube on 4/17/2024 in #djs-questions
Button Interaction
Hey, heres my code: buttonCollector.on('collect', async buttonInteraction => { console.log(buttonInteraction.customId); if (buttonInteraction.customId === 'accept') { const paymentMethods = allowedUsers[freelancerId];; const paypalButton = new ButtonBuilder() .setCustomId('paypal') .setLabel('PayPal') .setStyle(ButtonStyle.Primary); const cashAppButton = new ButtonBuilder() .setCustomId('cashapp') .setLabel('CashApp') .setStyle(ButtonStyle.Primary); const paymentActionRow = new ActionRowBuilder() .addComponents(paypalButton, cashAppButton); const acceptEmbed = new EmbedBuilder() .setTitle('Payment Options') .setDescription('Please select a payment method:') .setColor('Blue'); await buttonInteraction.update({ embeds: [acceptEmbed], components: [paymentActionRow] }); } else if (buttonInteraction.customId === 'decline') { buttonInteraction.reply({ content: 'Payment request declined.', ephemeral: true }); } else if (buttonInteraction.customId === 'decline') { buttonInteraction.reply({ content: 'Payment request declined.', ephemeral: true }); } });. It doesnt seem to be getting here, did I do smth wrong?
31 replies
DIAdiscord.js - Imagine an app
Created by GustyCube on 4/16/2024 in #djs-questions
A few errors.
Hey, I have a few erros, I havent encountered some because of my initial problem. Heres my code attached. Basically, I want it to only show users from the freelancer.json file like this: { "1162498330908180500" :{ "PayPal": "", "CashApp": "" } }, however its showing everything and no matter what i try i get an error. Any other bug catching would be appreciated too!
13 replies
DIAdiscord.js - Imagine an app
Created by GustyCube on 4/15/2024 in #djs-questions
Error with commands
Hey, here is my code: const { ApplicationCommandOptionType, PermissionFlagsBits, } = require('discord.js');
module.exports = { deleted: false, name: 'embed', description: 'Embed a certain message!', // devOnly: Boolean, // testOnly: Boolean, options: [ { name: 'embed', description: 'The embed to send.', required: true, type: ApplicationCommandOptionType.String, choices: [ { name: 'rules', value: '1', }, ], }, ], permissionsRequired: [PermissionFlagsBits.Administrator], botPermissions: [PermissionFlagsBits.Administrator],
callback: (interaction) => { console.log('Interaction options:', interaction.options);
const category = interaction.options.getString('embed'); console.log('Embed option:', embed);
if (embed && embed.value === "rules") { // Perform actions specific to the embed command with the whyimbetter option value of 1 interaction.reply('Embed with whyimbetter option value of 1'); } else { // Perform actions specific to the embed command without the whyimbetter option interaction.reply('Embed without whyimbetter option'); } }, }; It generates: ⏩ Skipping registering command "ban" as it's set to delete. Interaction options: { closeTimeout: 5000, waitGuildTimeout: 15000, shardCount: 1, makeCache: [Function (anonymous)], partials: [], failIfNotExists: true, presence: { status: 'online', user: { id: null } }, sweepers: { threads: { interval: 3600, lifetime: 14400 } }, ws: { large_threshold: 50, version: 10, presence: { activities: [], afk: false, since: null, status: 'online' } }, rest: { agent: null, api: 'https://discord.com/api', authPrefix: 'Bot', cdn: 'https://cdn.discordapp.com', headers: {}, invalidRequestWarningInterval: 0, globalRequestsPerSecond: 50, offset: 50, rejectOnRateLimit: null, retries: 3, timeout: 15000, userAgentAppendix: undefined, version: '10', hashSweepInterval: 14400000, hashLifetime: 86400000, handlerSweepInterval: 3600000, makeRequest: [AsyncFunction: makeRequest] }, jsonTransformer: [Function: toSnakeCase], intents: IntentsBitField { bitfield: 33283 }, shards: [ 0 ] } There was an error running this command: TypeError: interaction.options.getString is not a function
5 replies
DIAdiscord.js - Imagine an app
Created by GustyCube on 4/12/2024 in #djs-questions
Making a /command
Hi, how would I go about making a command where any .js file in the folder /commands gets registered, and how do I register commands? I can’t get them to work. I want it to be guild only.
7 replies