#'await' expressions are only allowed within async functions and at the top levels of modules

68 messages · Page 1 of 1 (latest)

earnest sinew
#

Look at the guide code's first line, and now look at your code's 7th line, you're missing async, you can only use await in async functions or at the top levels of modules

thorn marsh
#

ohh

#

thanks

#

also the command its not working

earnest sinew
#

Of course, and what do you mean by "not working", what happens when you use it? Any errors?

thorn marsh
#

i write the command and nothing happens

#

did i missed something?

earnest sinew
thorn marsh
#

nope, nothing

#

its like the script its not seeing my commands folder and command file

earnest sinew
#

Did you run the script?

thorn marsh
#

what? node .\index.js isn't that the command that runs the entire script?

earnest sinew
#

Once you fill in these values, run node deploy-commands.js in your project directory to register your commands to the guild specified. If you see the success message, check for the commands in the server by typing /! If all goes well, you should be able to run them and see your bot's response in Discord!

thorn marsh
#

i did that

earnest sinew
#

Does the command show on Discord?

thorn marsh
#

thats why i am asking u, i know i am stupid but not that stupid

#

haha

thorn marsh
earnest sinew
#

Can you show deploy-commands.js?

thorn marsh
#

i've just copy pasted from the guide

#

the clientId i took it from there

#

and the guildId from there:

analog kelp
#

Refresh discord sometimes fix the issue

thorn marsh
#

i started develop a command by myself

#

but i get this error

#
const { SlashCommandBuilder } = require('discord.js');

module.exports = {
    cooldown: 5,
    data: new SlashCommandBuilder()
        .setName('to')
        .setDescription('Activeaza ticketele!'),
    async execute(interaction) {
        // Set the allowed role IDs
        const allowedRoleIds = ['1084567084224217178', '1090427272059695224'];

        // Check if the user invoking the command has one of the allowed roles
        const hasAllowedRole = interaction.member.roles.cache.some(role => allowedRoleIds.includes(role.id));
        if (!hasAllowedRole) {
            return interaction.reply({
                content: 'Nu ai permisiunea de a folosi aceasta comanda.',
                ephemeral: true
            });
        }

        // Get the channel where you want to create the button
        const channel = interaction.client.channels.cache.get('1090749603625832608');

        // Create the message with the button
        const message = await channel.send({
            content: 'Click this button to do something!',
            components: [{
                type: 'ACTION_ROW',
                components: [{
                    type: 'BUTTON',
                    style: 'PRIMARY',
                    label: 'Click me!',
                    customId: 'button_click'
                }]
            }]
        });

        await interaction.reply('Button created!');
    },
};
#

i just want to send a button to another channel if the user that write the command has the permision

wet falcon
#

you should use ActionRowBuilder and ButtonBuilder instead of manually writing them as an object. it's complaining that there's no toJSON function on your button since it's just a simple object

thorn marsh
#

now i get this

wet falcon
#

MessageBuilder on line 118, is that a real class? i dont see it anywhere

harsh raptor
thorn marsh
#

why do i get that?

harsh raptor
#

And what exactly is tickets line 117

thorn marsh
#

14.8.0

harsh raptor
#

Personally I’d recommend just using the builders

thorn marsh
harsh raptor
#

It prevents errors like these quite a lot

harsh raptor
thorn marsh
#

i just want when i press this button to show me this:

harsh raptor
#

So use an interactionCreate outside of that file and handle everything in one event

thorn marsh
#

all what i have in my script its not the same as in the guide

thorn marsh
#
client.on('interactionCreate', async interaction => {
    if (!interaction.isButton()) return;

    if (interaction.customId === 'primary') {
        const modal = new ModalBuilder()
            .setCustomId('modal-tickets')
            .setTitle('Cox Family Support - Tickets');

        const problemInput = new TextInputBuilder()
            .setCustomId('problemInput')
            .setLabel("In ce problema dorest sa ne contactezi?")
            .setStyle(TextInputStyle.Paragraph);

        const selectMenu = new SelectMenuBuilder()
            .setCustomId('select')
            .setPlaceholder('Nothing selected')
            .addOptions(
                {
                    label: 'Select me',
                    description: 'This is a description',
                    value: 'first_option',
                },
                {
                    label: 'You can select me too',
                    description: 'This is also a description',
                    value: 'second_option',
                },
            );


        const firstActionRow = new ActionRowBuilder()
            .addComponents(problemInput, selectMenu);

        modal.addComponents(firstActionRow);
        await interaction.showModal(modal);
    }
});```
#

i just want to add the constant selectMenu

#

why its not working like the inputs?

thorn marsh
#

what is this?

#

DiscordAPIError[50035]: Invalid Form Body
name[BASE_TYPE_REQUIRED]: This field is required
at SequentialHandler.runRequest (C:\Users\sstru\Desktop\cox-bots\ticket-bot\node_modules@discordjs\rest\dist\index.js:933:15)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async SequentialHandler.queueRequest (C:\Users\sstru\Desktop\cox-bots\ticket-bot\node_modules@discordjs\rest\dist\index.js:712:14)
at async REST.request (C:\Users\sstru\Desktop\cox-bots\ticket-bot\node_modules@discordjs\rest\dist\index.js:1321:22)
at async GuildChannelManager.create (C:\Users\sstru\Desktop\cox-bots\ticket-bot\node_modules\discord.js\src\managers\GuildChannelManager.js:170:18)
at async Client.<anonymous> (C:\Users\sstru\Desktop\cox-bots\ticket-bot\index.js:63:21) {
rawError: {
code: 50035,
errors: { name: [Object] },
message: 'Invalid Form Body'
},
code: 50035,
status: 400,
method: 'POST',
url: 'https://discord.com/api/v10/guilds/1084566469767069827/channels',
requestBody: {
files: undefined,
json: {
name: undefined,
topic: undefined,
type: undefined,
nsfw: undefined,
bitrate: undefined,
user_limit: undefined,
parent_id: undefined,
position: undefined,
permission_overwrites: undefined,
rate_limit_per_user: undefined,
rtc_region: undefined,
video_quality_mode: undefined,
available_tags: undefined,
default_reaction_emoji: undefined,
default_auto_archive_duration: undefined,
default_sort_order: undefined,
default_forum_layout: undefined
}
}
}

tropic plank
#

An error telling you that channels need a name when creating them

thorn marsh
#

the modal popup is not closing

#

i dont get any errors