Repository

discord.v

Discord API implementation library written in V

Support server Documentation

Credits

Creator: nerdarp

Installing

From Git directly:

$ v install --git https://github.com/DarpHome/discord.v

With VPM (soon, use Git):

$ v install DarpHome.discord

Examples

Ping pong

module main

import discord
import os

fn main() {
    mut c := discord.bot(os.getenv_opt('DISCORD_BOT_TOKEN') or {
        eprintln('No token specified')
        exit(1)
    }, intents: .message_content | .guild_messages)
    c.events.on_ready.listen(fn (event discord.ReadyEvent) ! {
        println('Logged as ${event.user.username}! Bot has ${event.guilds.len} guilds')
    })
    c.events.on_message_create.listen(fn (event discord.MessageCreateEvent) ! {
        if event.message.content != '!ping' {
            return
        }
        event.creator.create_message(event.message.channel_id, content: 'Pong')!
    })
    c.launch()!
}

[!NOTE] Returning an error from event handler logs error, not panic the whole program. Don't forget enable Message Content intent in Developer Portal! Otherwise, your bot will shutdown with error:

...
2023-12-21 18:46:20.237000 [ERROR] Websocket closed with 4014 Disallowed intent(s).
2023-12-21 18:46:20.237000 [INFO ] Quit client listener, server(false)...
2023-12-21 18:46:20.238000 [ERROR] Recieved close code 4014: Disallowed intent(s): You sent a disallowed intent for a 
Gateway Intent. You may have tried to specify an intent that you have not enabled or are not approved for.
V panic: result not set (Disallowed intent(s): You sent a disallowed intent for a Gateway Intent. You may have tried to
specify an intent that you have not enabled or are not approved for.)      
...

TODO (stolen from Terisback 💀)

First milestone

  • Connect to gateway
  • Handle heartbeat
  • Event system (pub/sub)
  • REST for sending messages
  • Implement multipart/form-data for file sending
  • Do usual application/json for sending without binary data
  • Handle Gateway events
    • Audit Log
    • Channel
    • Emoji
    • Guild
    • Invite
    • User
    • Voice
    • Webhook
    • Slash Command
  • Create examples (3/4)
  • Documentation

Second milestone

  • Handle REST
    • Interactions
      • Application Commands
      • Message Components
      • Receiving and Responding
    • Resources
      • Application
      • Application Role Connection Metadata
      • Audit Log
      • Auto Moderation
      • Channel
      • Emoji
      • Guild
      • Guild Scheduled Event
      • Guild Template
      • Invite
      • Stage Instance
      • Sticker
      • User
      • Voice
      • Webhook
  • Command router
  • Think about tests

Third milestone (till V v0.5)

  • Build cache ontop map's (memcache, redis in future)

The Main one

  • Make a cool library

About

Discord API wrapper

0
4
last Jan 11

Author

MCausc78