Skip to content

Latest commit

 

History

History
120 lines (100 loc) · 2.99 KB

README.md

File metadata and controls

120 lines (100 loc) · 2.99 KB

discord.v

Discord API implementation library written in V

Support server | Documentation

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