aiko-chan-ai / discord.js-selfbot-v13

An unofficial discord.js fork for creating selfbots
https://discordjs-self-v13.netlify.app
GNU General Public License v3.0
799 stars 169 forks source link

Send slash commmand #5

Closed pwaillette closed 2 years ago

pwaillette commented 2 years ago

Hello, I don't understand how to send slash commands ? I have an error with the example code :

    const command = application.cache.first();
                                      ^

TypeError: Cannot read properties of undefined (reading 'first')
    at Client.<anonymous> (/Users/aiko/Desktop/Developpement/Projets/JavaScript/Test/index.js:15:39)

My code are :

client.on("message", async (message) => {
  if (message.content === "aaa") {
    const botID = "mudae_id";
    const user = await client.users.fetch(botID);
    const application = await user.applications.fetch();
    console.log(application);
    const command = application.cache.first();
    // Message: Discord.Message, using Message contructor create
    /*
guildID: Guild.id || null,
channelID: Channel.id,
messageID: Message.id,
*/
    await command.sendSlashCommand(message, ["profil"]);
    // Eg: Slash /add role:123456789 user:987654321
    // value: ['123456789', '987654321']
    // Channel.sendSlashCommand(botID, commandName, options): Comming soon !
  }
});

Can you help me, or explain to me how slash commands send work ?

pwaillette commented 2 years ago

I have take only the example code. Is it correct ?

aiko-chan-ai commented 2 years ago

I have take only the example code. Is it correct ?

oh , i think you forgot something here user.applications.fetch() returns Promise\<Collection> therefore

const command = application.cache.first();

you need to change it to

const command = application.first();
aiko-chan-ai commented 2 years ago

Hello, I don't understand how to send slash commands ? I have an error with the example code :

    const command = application.cache.first();
                                      ^

TypeError: Cannot read properties of undefined (reading 'first')
    at Client.<anonymous> (/Users/aiko/Desktop/Developpement/Projets/JavaScript/Test/index.js:15:39)

My code are :

client.on("message", async (message) => {
  if (message.content === "aaa") {
    const botID = "mudae_id";
    const user = await client.users.fetch(botID);
    const application = await user.applications.fetch();
    console.log(application);
    const command = application.cache.first();
    // Message: Discord.Message, using Message contructor create
    /*
guildID: Guild.id || null,
channelID: Channel.id,
messageID: Message.id,
*/
    await command.sendSlashCommand(message, ["profil"]);
    // Eg: Slash /add role:123456789 user:987654321
    // value: ['123456789', '987654321']
    // Channel.sendSlashCommand(botID, commandName, options): Comming soon !
  }
});

Can you help me, or explain to me how slash commands send work ?

I updated the new slash command usage