+
Skip to content

TypeError: this.client.setInterval is not a function #243

@yanchespenda

Description

@yanchespenda

I'm trying a simple ping bot, and I found a error in client command

index.js

require('dotenv').config()
const { AkairoClient, CommandHandler, ListenerHandler } = require('discord-akairo');
const { Intents } = require('discord.js');
const { join } = require('path');

class MyClient extends AkairoClient {
  constructor() {
    super({
      ownerID: "514546889874472990"
      // Options for Akairo go here.
    }, {
      // Options for discord.js goes here.
      intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES]
    });

    this.commandHandler = new CommandHandler(this, {
      prefix: ['a!'],
      // blockBots: true,
      // blockClient: true,
      // allowMention: true,
      // defaultCooldown: 500,
      // commandUtil: true,
      directory: join(__dirname, "commands")
    });

    this.listenerHandler = new ListenerHandler(this, {
      directory: join(__dirname, "listeners")
    });

    this.commandHandler.useListenerHandler(this.listenerHandler);
    this.listenerHandler.loadAll();
    this.commandHandler.loadAll();
  }
}

const client = new MyClient();
client.login(process.env.DISCORD_TOKEN);

/commands/ping.js

const { Command } = require('discord-akairo');

class Ping extends Command {
  constructor() {
    super('ping', {
      aliases: ['ping', 'pong'],
      channel: 'guild',
      category: 'Utilities',
      description: {
          content: 'This provides the ping of the bot.'
      }
    });
  }

  async exec(message) {

    const msg = await message.channel.send('Pinging...');

    const latency = msg.createdTimestamp - message.createdTimestamp;
    const choices = ['Is this really my ping?', 'Is that okay? I can\'t look!', 'I hope it isn\'t bad!'];
    const reponse = choices[Math.floor(Math.random() * choices.length)];

    msg.edit(`${reponse} - **Bot Latency**: \`${latency}ms\`, **API Latency**: \`${Math.round(this.client.ws.ping)}ms\``)

  }
}

module.exports = Ping;

/listeners/ready.js


class Ready extends Listener {
  constructor() {
    super('ready', {
      event: 'ready',
      emitter: 'client'
    });
  }

  exec() {

    // let i = 0;
    setInterval(() => this.client.user.setActivity(`a!help | Powered by Akairo`, { type: 'WATCHING' }), 15000);

    console.log(`${this.client.user.tag} is online!`);

  }
}

module.exports = Ready;

Error message:
Screenshot (17)

How to solve this ? thanks

Windows 11
NodeJs 16.10
discord-akairo 8.1.0
discord.js 13.2.0
yarn 3.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载