# Creating a new project

  • This guide will explain you how to create your first bot with cofo!

# Installation

  • Cofo Framework is on the npm registry, You can install it via any package manager.
  • Create the package.json via the initalize command:
  • Npm
  • Yarn
  • Pnpm
npm init -y

# Typescript

  • For Typescript, Kindly install typescript,@types/node as devDependencies.

  • Once installed all the required dependencies, Install @cofo/framework
  • Npm
  • Yarn
  • Pnpm
npm i @cofo/framework

# Structure

  • Once you've installed the framework, create the base structure as follows:
.
├── my-project
│   ├── `src`
│   │   ├── `Commands`
│   │   │   ├── `General`
│   │   │       └── PingCommand.ts
│   │   ├── `Listeners`
│   │   │   ├── ReadyListener.ts
│   │   ├── index.ts
│   ├── package.json
  • Then, Lets Start writing the code

  • src/index

  • Javascript
  • Typescript
const { CofoClient } = require("@cofo/framework");

const client = new CofoClient(
  `Bot ${process.env.TOKEN}`,
  {
    baseDirectory: `${process.cwd()}/src/`, // Basically the directory where the commands and listeners folder shall be located (required)
    defaultPrefix: "!", // The Default Prefix to use if no custom prefix / mention prefix enabled (required)
    mentionPrefix: true, // Whether to take mention as a prefix or not (required)
    owners: [], // The Bot Owners, (required), This is required for botOwnerOnly commands.
    testMode: {
      // Whether the bot is in development mode, if enabled provide a guild id where the slash commands would be registered (not compulsory)
      enabled: true,
      guildID: "928880438641041480",
    },
  }, // Eris Options:
  {
    intents: ["guildMembers", "guildMessages", "guilds"],
    restMode: true, // Recommended
  }
);

client.connect()
  • src/commands/General/PingCommand.ts
  • Javascript
  • Typescript
const { Command } = require("@cofo/framework");

module.exports = class PingCommand extends Command {
  constructor(client) {
    super(client, {
      name: "mycommandname",
      description: "mycommanddescription",
    });
  }
  /**
   * Message Command
   * @param {Client} client
   * @param {Message} message
   */
  messageRun(client, message) {
    message.channel.createMessage({
      content: "Pong!",
    });
  }
  /**
   * Slash Command
   * @param {Client} client
   * @param {Interaction} interaction
   */
  interactionRun(client, interaction) {
    interaction.createMessage({
      content: "Pong!",
    });
  }
};
  • src/listeners/ReadyListener.ts
  • Javascript
  • Typescript
const { Listener } = require('@cofo/framework');

module.exports = new Listener("ready", async(client) => {
  console.log(`Client has connected`)
})

# Using a custom prefix

  • Cofo supports 3 types of prefix: Mention, custom and a default

  • For a custom prefix we send you the message as a parameter and you need to return a string as follows:

client.fetchPrefix = (message) => {
  db.getguild(message.guildID).then(data => {
    return data.prefix
  })
}