Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

130
Visualizações
Pass the bot configuration file so that it is accessible globally from Client

I'm wanting to pass my bot's configuration file (config.json) into the bot client so I can get for example, the bot's owner ID instead of specifying it in each command that I want only the bot owner to access, or the embed footer text, example:

    async execute(client, message, args, footerTxt) {
        if (message.author.id == BotOwnerId) {

I want to be able to just have it be

       async execute(client, message, args){
                if (message.author.id == client.config.ownerID) {

I have tried running it through the command execute

    try {
        await client.commands.get(command).execute(client, message, args, footerTxt, config);
    } catch (error) {

which resulted in

TypeError: Cannot read properties of undefined (reading 'ownerID')
at Object.execute
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

config.json

{
   "ownerID": "XXXXXXXXXXX",
   "someOtherStuff": [],
   "someMoreStuff": { "id": 1, "name": "Test" }
}

index (assuming config.json is in the same folder)

const config = require('./config.json')

await client.commands.get(command).execute(client, message, args, footerTxt, config);

cmd:

if (message.author.id == config.ownerID) {

Why not simply requiring the config file in index and passing it through the args to the command? Or require it in the commands? As you wish but it should do the trick

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda