harmony/README.md

176 lines
4.1 KiB
Markdown
Raw Normal View History

2020-12-02 10:52:11 +00:00
![banner](https://cdn.discordapp.com/attachments/783319033730564098/783399012547035176/HarmonyBanner.png)
2020-12-02 10:48:55 +00:00
<p align=center><i><b>An easy to use Discord API Library for Deno</b></i></p>
<p align=center>
<img src="https://img.shields.io/badge/standard--readme-OK-green.svg?style=for-the-badge"/>
<a href=https://discord.gg/WVN2JF2FRv>
<img src="https://img.shields.io/discord/783319033205751809.svg?label=Discord&logo=Discord&colorB=7289da&style=for-the-badge" alt="Support">
</a>
</p>
<br>
- Lightweight and easy to use.
- Complete Object-Oriented approach.
- Slash Commands supported.
- Built-in Commands framework.
- Customizable Caching, with Redis support.
- Use `@decorators` to easily make things!
- Made with ❤️ TypeScript.
2020-11-02 16:09:12 +00:00
## Table of Contents
- [Usage](#usage)
- [Docs](#docs)
2020-12-02 04:30:14 +00:00
- [Discord](#discord)
2020-11-03 23:00:03 +00:00
- [Maintainer](#maintainer)
2020-11-02 16:09:12 +00:00
- [Contributing](#contributing)
- [License](#license)
## Usage
2020-12-02 10:48:55 +00:00
2021-01-21 14:57:06 +00:00
You can import the package from https://deno.land/x/harmony/mod.ts (with latest version) or can add a version too, and raw GitHub URL (latest unpublished version) https://raw.githubusercontent.com/harmonyland/harmony/main/mod.ts too.
For a quick example, run this:
2020-12-02 10:48:55 +00:00
```bash
2020-12-03 11:07:35 +00:00
deno run --allow-net https://deno.land/x/harmony/examples/ping.ts
```
2020-12-02 10:48:55 +00:00
And input your bot's token and Intents.
2020-11-02 16:09:12 +00:00
2020-11-08 07:29:06 +00:00
Here is a small example of how to use harmony,
2020-12-02 10:48:55 +00:00
2020-11-02 16:09:12 +00:00
```ts
2021-02-02 05:21:12 +00:00
import {
Client,
Message,
GatewayIntents
} from 'https://deno.land/x/harmony/mod.ts'
const client = new Client()
2020-11-02 16:09:12 +00:00
// Listen for event when client is ready (Identified through gateway / Resumed)
client.on('ready', () => {
console.log(`Ready! User: ${client.user?.tag}`)
})
2020-11-02 16:09:12 +00:00
// Listen for event whenever a Message is sent
client.on('messageCreate', (msg: Message): void => {
2020-11-02 16:09:12 +00:00
if (msg.content === '!ping') {
msg.channel.send(`Pong! WS Ping: ${client.ping}`)
2020-11-02 16:09:12 +00:00
}
})
// Connect to gateway
2021-02-02 05:21:12 +00:00
client.connect('super secret token comes here', [
GatewayIntents.DIRECT_MESSAGES,
GatewayIntents.GUILDS,
GatewayIntents.GUILD_MESSAGES
])
2020-11-02 16:09:12 +00:00
```
2020-11-07 09:14:28 +00:00
Or with CommandClient!
2020-12-02 10:48:55 +00:00
2020-11-07 09:14:28 +00:00
```ts
2020-12-02 10:48:55 +00:00
import {
CommandClient,
Command,
CommandContext,
2021-02-02 05:21:12 +00:00
GatewayIntents
2020-12-03 11:07:35 +00:00
} from 'https://deno.land/x/harmony/mod.ts'
2020-11-07 09:14:28 +00:00
const client = new CommandClient({
2020-12-02 12:29:52 +00:00
prefix: '!'
2020-11-07 09:14:28 +00:00
})
// Listen for event when client is ready (Identified through gateway / Resumed)
client.on('ready', () => {
console.log(`Ready! User: ${client.user?.tag}`)
})
// Create a new Command
class PingCommand extends Command {
2020-12-02 10:48:55 +00:00
name = 'ping'
2020-11-07 09:14:28 +00:00
execute(ctx: CommandContext) {
ctx.message.reply(`pong! Ping: ${ctx.client.ping}ms`)
}
}
client.commands.add(PingCommand)
// Connect to gateway
2021-02-02 05:21:12 +00:00
client.connect('super secret token comes here', [
GatewayIntents.DIRECT_MESSAGES,
GatewayIntents.GUILDS,
GatewayIntents.GUILD_MESSAGES
])
2020-11-07 09:14:28 +00:00
```
2020-12-17 08:59:36 +00:00
Or with Decorators!
2020-12-14 13:24:53 +00:00
```ts
import {
event,
2021-02-02 05:21:12 +00:00
CommandClient,
2020-12-14 13:24:53 +00:00
command,
2021-02-02 05:21:12 +00:00
CommandContext,
GatewayIntents
2020-12-14 13:24:53 +00:00
} from 'https://deno.land/x/harmony/mod.ts'
class MyClient extends CommandClient {
constructor() {
super({
prefix: ['!', '!!'],
caseSensitive: false
})
}
@event()
ready(): void {
console.log(`Logged in as ${this.user?.tag}!`)
}
@command({ aliases: 'pong' })
Ping(ctx: CommandContext): void {
ctx.message.reply('Pong!')
}
}
2021-02-02 05:21:12 +00:00
new MyClient().connect('super secret token comes here', [
GatewayIntents.DIRECT_MESSAGES,
GatewayIntents.GUILDS,
GatewayIntents.GUILD_MESSAGES
])
2020-12-14 13:24:53 +00:00
```
2020-11-02 16:09:12 +00:00
## Docs
2020-12-03 09:38:55 +00:00
Documentation is available for `main` (branch) and `stable` (release).
2020-12-05 07:20:08 +00:00
2021-01-21 14:57:06 +00:00
- [Main](https://doc.deno.land/https/raw.githubusercontent.com/harmonyland/harmony/main/mod.ts)
2020-12-03 09:38:55 +00:00
- [Stable](https://doc.deno.land/https/deno.land/x/harmony/mod.ts)
2021-01-21 14:57:06 +00:00
- [Guide](https://harmony.mod.land)
2020-11-02 16:09:12 +00:00
2020-12-02 10:48:55 +00:00
## Found a bug or want support? Join our discord server!
2020-12-02 04:30:14 +00:00
[![Widget for the Discord Server](https://discord.com/api/guilds/783319033205751809/widget.png?style=banner1)](https://discord.gg/WVN2JF2FRv)
2020-11-03 23:00:03 +00:00
## Maintainer
2020-11-02 16:09:12 +00:00
[@Helloyunho](https://github.com/Helloyunho)
## Contributing
See [the contributing file](CONTRIBUTING.md)!
2020-12-02 10:48:55 +00:00
Pull Requests are accepted.
2020-11-02 16:09:12 +00:00
Small note: If editing the README, please conform to the [standard-readme](https://github.com/RichardLitt/standard-readme) specification.
## License
2021-01-21 14:57:06 +00:00
[MIT © 2020-2021 Harmonyland](LICENSE)
2020-12-02 10:48:55 +00:00
2021-01-21 14:57:06 +00:00
#### Made with ❤ by Harmonyland