Skocz do zawartości
  • 0

Pomoc discord.js visual studio code


lxkit
 Udostępnij

Pytanie

witam, chciałem odpalic mojego bota poprzez komende "node ." , lecz wyskakuje mi taki błąd

Node.js v18.14.2
PS D:\71Bot_folder> node .
D:\71Bot_folder\index.js:12
if (interaction.isCommand()) return;
^

ReferenceError: interaction is not defined
    at Object.<anonymous> (D:\71Bot_folder\index.js:12:1)
    at Module._compile (node:internal/modules/cjs/loader:1254:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1308:10)
    at Module.load (node:internal/modules/cjs/loader:1117:32)
    at Module._load (node:internal/modules/cjs/loader:958:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
    at node:internal/main/run_main_module:23:47

 

A tutaj plik index.js

 

require('dotenv').config();



const {REST} = require('@discordjs/rest');

const { Routes } = require('discord-api-types/v9');

const { Client, Intents, Collection, GatewayIntentBits } = require('discord.js');

const { Player } = require("discord-player")

const { InteractionType} = require("discord.js")

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



const fs = require('fs');

const path = require('path');

if (interaction.isCommand()) return;



const client = new Client({

    intents: [

        GatewayIntentBits.GUILDS, GatewayIntentBits.GUILD_MESSAGES, GatewayIntentBits.GUILD_VOICE_STATES

    ]

});



// List of all commands

const commands = [];

client.commands = new Collection();



const commandsPath = path.join(__dirname, "commands"); // E:\yt\discord bot\js\intro\commands

const commandFiles = fs.readdirSync(commandsPath).filter(file => file.endsWith('.js'));

for(const file of commandFiles)

{

    const filePath = path.join(commandsPath, file);

    const command = require(filePath);



    client.commands.set(command.data.name, command);

    commands.push(command.data.toJSON());

}



// Add the player on the client

client.player = new Player(client, {

    ytdlOptions: {

        quality: "highestaudio",

        highWaterMark: 1 << 25

    }

})



client.on("ready", () => {

    // Get all ids of the servers

    const guild_ids = client.guilds.cache.map(guild => guild.id);




    const rest = new REST({version: '9'}).setToken(process.env.TOKEN);

    for (const guildId of guild_ids)

    {

        rest.put(Routes.applicationGuildCommands(process.env.CLIENT_ID, guildId),

            {body: commands})

        .then(() => console.log('Successfully updated commands for guild ' + guildId))

        .catch(console.error);

    }

});



client.on("interactionCreate", async interaction => {

    if(!interaction.isCommand()) return;



    const command = client.commands.get(interaction.commandName);

    if(!command) return;



    try

    {

        await command.execute({client, interaction});

    }

    catch(error)

    {

        console.error(error);

        await interaction.reply({content: "There was an error executing this command"});

    }

});



client.login(process.env.TOKEN);

 

Odnośnik do komentarza
Udostępnij na innych stronach

0 odpowiedzi na to pytanie

Rekomendowane odpowiedzi

Nie udzielono jeszcze odpowiedzi na to pytanie

Jeśli chcesz dodać odpowiedź, zaloguj się lub zarejestruj nowe konto

Jedynie zarejestrowani użytkownicy mogą komentować zawartość tej strony.

Zarejestruj nowe konto

Załóż nowe konto. To bardzo proste!

Zarejestruj się

Zaloguj się

Zaloguj się poniżej.

Zaloguj się
 Udostępnij

  • Ostatnio przeglądający forum Pomoc discord.js visual studio code   0 użytkowników
    • Brak zarejestrowanych użytkowników przeglądających tę stronę.
×
×
  • Dodaj nową pozycję...