#Autocomplete Error!

31 messages · Page 1 of 1 (latest)

near mangoBOT
#

• What's your exact discord.js npm list discord.js and node node -v version?
• Post the full error stack trace, not just the top part!
• Show your code!
• Explain what exactly your issue is.
• Not a discord.js issue? Check out #useful-servers.

formal sentinelBOT
wraith gust
#

You didn’t add an autocomplete function to that commands exports

teal whale
#

i did

wraith gust
#

Error disagrees

teal whale
#
    constructor(client) {
        super(client, {
            data: new SlashCommandBuilder()
                .setName('akinator')
                .setDescription('Play Akinator Game.')
                .setDMPermission(true)
                .addStringOption(option =>
                    option.setName(`language`)
                        .setDescription(`In Which Language You Want To Play Akinator`)
                        .setRequired(true)
                        .setAutocomplete(true)),
            async autocomplete(interaction) {
                const focusedValue = interaction.options.getFocused();
                const choices = ['Popular Topics: Threads', 'Sharding: Getting started', 'Library: Voice Connections', 'Interactions: Replying to slash commands', 'Popular Topics: Embed preview'];
                const filtered = choices.filter(choice => choice.includes(focusedValue));
                await interaction.respond(
                    filtered.map(choice => ({ name: choice, value: choice })),
                );
            },
            usage: 'akinator',
            category: 'akinator',
            permissions: ['Use Application Commands', 'Send Messages', 'Embed Links'],
        });
    }
    async run(client, interaction) {

        
    }
};```
wraith gust
#

You added it to the object you pass to the superclass‘s constructor. Not to the class…

teal whale
#

now what should i do

#

@wraith gust

wraith gust
#

Do what I said you didn’t do instead of what you did do

#

It needs to be a function/method of the class

teal whale
#

Kk

#

Like This???

module.exports = class Akinator extends Command {
    constructor(client) {
        super(client, {
            data: new SlashCommandBuilder()
                .setName('akinator')
                .setDescription('Play Akinator Game.')
                .setDMPermission(true)
                .addStringOption(option =>
                    option.setName(`language`)
                        .setDescription(`In Which Language You Want To Play Akinator`)
                        .setRequired(true)
                        .setAutocomplete(true)),
            usage: 'akinator',
            category: 'akinator',
            permissions: ['Use Application Commands', 'Send Messages', 'Embed Links'],
        });
    }

    async autocomplete(interaction) {
        const focusedValue = interaction.options.getFocused();
        const choices = ['Popular Topics: Threads', 'Sharding: Getting started', 'Library: Voice Connections', 'Interactions: Replying to slash commands', 'Popular Topics: Embed preview'];
        const filtered = choices.filter(choice => choice.includes(focusedValue));
        await interaction.respond(
            filtered.map(choice => ({ name: choice, value: choice })),
        );
    }

    async run(client, interaction) {
        // Your command logic goes here
    }
};
#

@wraith gust

wraith gust
teal whale
#

kk

wraith gust
#

And you can also check yourself by running, no need to ask me when you already have node to answer that question for you

teal whale
#

not working above one

wraith gust
#

Any errors?

teal whale
#

Yup Same Error

wraith gust
#

console.log(command) before your command.autocomplete call then

teal whale
#

kk

#
  name: 'akinator',
  description: 'Play Akinator Game.',
  options: [
    {
      choices: undefined,
      autocomplete: true,
      type: 3,
      name: 'language',
      name_localizations: undefined,
      description: 'In Which Language You Want To Play Akinator',
      description_localizations: undefined,
      required: true,
      max_length: undefined,
      min_length: undefined
    }
  ],
  defaultPermission: undefined,
  contextDescription: null,
  usage: 'akinator',
  category: 'akinator',
  permissions: [ 'Use Application Commands', 'Send Messages', 'Embed Links' ],
  run: [AsyncFunction: run]
}```
wraith gust
#

You didn’t seem to have saved or your Command class does some magic stuff to add that run there but not the autocomplete

#

But I get the feeling you didn’t write that command class yourself but instead either use a framework or followed a tutorial. So ask whoever maintains that how to add autocomplete correctly in there

teal whale
#

yes

#
    constructor(client, meta = {}) {
        this.client = client;
        this.data = meta.data;
        this.contextDescription = meta.contextDescription || null;
        this.usage = meta.usage || this.name;
        this.category = meta.category || 'Info';
        this.permissions = meta.permissions || ['Use Application Commands', 'Send Messages', 'Embed Links'];
    }
    async run() {

        throw new Error(`The Slash Command "${this.name}" does not provide a run method.`);

    }
};```
#

Command Class

#

can you help me now

#

@wraith gust

wraith gust