Node.js v18.16.0 PS C:\Users\lidor\Desktop\Trade Bot> node index.js\ Logged in as Trade…
- User
Node.js v18.16.0 PS C:\Users\lidor\Desktop\Trade Bot> node index.js
Logged in as Trade Bot#5498! node:events:491 throw er; // Unhandled 'error' event ^DiscordAPIError[50035]: Invalid Form Body data.components[4].components[0][UNION_TYPE_CHOICES]: Value of field "type" must be one of (4,). at handleErrors (C:\Users\lidor\Desktop\Trade Bot\node_modules@discordjs\rest\dist\index.js:640:13) at process.processTicksAndRejections (node:internal/process/task_queues:95:5) at async BurstHandler.runRequest (C:\Users\lidor\Desktop\Trade Bot\node_modules@discordjs\rest\dist\index.js:736:23) at async REST.request (C:\Users\lidor\Desktop\Trade Bot\node_modules@discordjs\rest\dist\index.js:1387:22) at async ChatInputCommandInteraction.showModal (C:\Users\lidor\Desktop\Trade Bot\node_modules\discord.js\src\structures\interfaces\InteractionResponses.js:253:5) at async Client. (C:\Users\lidor\Desktop\Trade Bot\index.js:81:5) Emitted 'error' event on Client instance at: at emitUnhandledRejectionOrErr (node:events:394:10) at process.processTicksAndRejections (node:internal/process/task_queues:84:21) { requestBody: { files: undefined, json: { type: 9, data: { custom_id: 'myModal', title: 'Trade Modal', components: [ { type: 1, components: [Array] }, { type: 1, components: [Array] }, { type: 1, components: [Array] }, { type: 1, components: [Array] }, { type: 1, components: [Array] } ] } } }, rawError: { code: 50035, errors: { data: { components: { '4': { components: [Object] } } } }, }, code: 50035, status: 400, method: 'POST', url: 'https://discord.com/api/v10/interactions/1114774957021483069/aW50ZXJhY3Rpb246MTExNDc3NDk1NzAyMTQ4MzA2OTptc2dDY0JIOVgxSGlpOTVoSTRZR3luZFFSTTB5cHlvNDl6R1NEdlNxWjNLOWZKZHk3QTh4TXo0UHlReEdQTHJvdDdpRVJPMGVyOTE3S0pLYnZCYzcwS3A3azVUU3FIQmhDSlczTzNlS2trckZrZ0NBNmFDVXdPNTF6WXYwcWh4Rw/callback' const { Client, GatewayIntentBits, ActionRowBuilder, Events, ModalBuilder, TextInputBuilder, TextInputStyle, ButtonBuilder, StringSelectMenuBuilder, StringSelectMenuOptionBuilder, } = require('discord.js'); const { executeTrade, estimateTrade } = require('./execute');
const tradeMap = new Map();
const privateKey1 = '0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80'; const token0Address1 = '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2'; const token1Address1 = '0xdAC17F958D2ee523a2206206994597C13D831ec7';
const client = new Client({ intents: [GatewayIntentBits.Guilds] });
const TOKEN = 'MTExNDcyNjM4NTIxMTE1NDUyMw.GbE4yh.xrd6OWTr-ppeNYeM2fz80HpktUZY1G3H_LW1Pw';
const confirmationButton = new ButtonBuilder().setCustomId('confirmTrade').setLabel('Confirm Trade').setStyle(1);
const confirmationActionRow = new ActionRowBuilder().addComponents(confirmationButton);
- Assistant
It seems like you are getting an error due to an invalid form body. The issue is with
typevalue being one of (4,) for your components.First, make sure you have the latest version of Discord.js installed, as there could be differences in how components are handled between versions.
Next, based on your code, the problem seems to be with the form body of your modal component or any other components you are adding inside modal.
According to Discord.js documentation, buttons should have a type of 2 and select menus should have a type of 3.
The error message is suggesting that one of the components has an incorrect type. I think the issue might be with the
slippageMenucomponent. You should assign the type for this component.To fix this issue, try checking and changing the type values for your components as necessary. Also, make sure you are using the correct version of Discord.js, which supports the components feature. If these suggestions still don't solve your problem, consider pasting only the problematic part of the code for further assistance.
- User
const slippageMenu = new StringSelectMenuBuilder() .setCustomId('slippageMenu') .setPlaceholder('Slippage Tolerance') .addOptions( new StringSelectMenuOptionBuilder().setLabel('0.1%').setValue('0.001'), new StringSelectMenuOptionBuilder().setLabel('0.5%').setValue('0.005'), new StringSelectMenuOptionBuilder().setLabel('1%').setValue('0.01'), new StringSelectMenuOptionBuilder().setLabel('5%').setValue('0.05') );
- Assistant
Your slippageMenu code looks correct, and it should create a string select menu with the specified options. However, since you're still facing the error, I would recommend making sure that you are using the correct version of Discord.js library that supports these features.
The latest version of Discord.js is v13.x.x, which supports components and other new features. You can update your Discord.js library to the latest version by running the following command in your terminal or command prompt:
bashnpm install discord.js@latestAfter updating the library, check if your issue still persists. If you still face any issues, provide more information about the actual problem along with the code snippet that causes it for assistance.