Skocz do zawartości

Dołącz do społeczności!

👋 Witaj na MPCForum!

Przeglądasz forum jako gość, co oznacza, że wiele świetnych funkcji jest jeszcze przed Tobą! 😎

  • ✅ Pełny dostęp do działów i ukrytych treści
  • ✅ Możliwość pisania i odpowiadania w tematach
  • ✅ System prywatnych wiadomości
  • ✅ Zbieranie reputacji i rozwijanie swojego profilu
  • ✅ Członkostwo w jednej z największych społeczności graczy

👉 Dołączenie zajmie Ci mniej niż minutę – a zyskasz znacznie więcej!

Zarejestruj się teraz

Pomoc discord.js visual studio code

Rekomendowane odpowiedzi

Opublikowano

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);

 

  • 11 miesięcy temu...

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

Ostatnio przeglądający 0

  • Brak zarejestrowanych użytkowników przeglądających tę stronę.

Konto

Nawigacja

Skonfiguruj powiadomienia push w przeglądarce

Chrome (Android)
  1. Stuknij ikonę kłódki obok paska adresu.
  2. Stuknij Uprawnienia → Powiadomienia.
  3. Dostosuj swoje ustawienie.
Chrome (Komputer)
  1. Kliknij ikonę kłódki na pasku adresu.
  2. Wybierz Ustawienia witryny.
  3. Znajdź Powiadomienia i dostosuj swoje ustawienie.