‎‎‎‎‎Create a serverless Discord bot in pure dart using Discord Interactions webhooks

Overview

Create a serverless Discord bot in pure dart using Discord Interactions webhooks

Features

Feature Status
Manage Application Commands Full support (unit-tested)
Create message components Full support (unit-tested)
Respond to commands Full support (unit-tested)
File uploads Full support (unit-tested)

Supported APIs

API Status
Audit Logs Full support (unit-tested)
Channels Full support (mostly unit-tested)
Emojis Full support (unit-tested)
Guilds Full support (mostly unit-tested)
Guild Scheduled Events Full support (untested)
Guild Templates Full support (untested)
Invites Full support (unit-tested)
Stage Instances Full support (untested)
Stickers Full support (partially unit-tested)
Users Full support (unit-tested)
Voice Full support (unit-tested)
Webhooks Full support (untested)

Full support for all Discord API endpoints is planned

Getting started

This package is meant for running a Discord bot on serverless platforms. The example is made for Google Cloud Run, but other providers that support running dart code will work.

Usage

Discord has a couple requirements that must be met before you can enable webhooks for Interactions. This package comes with helper functions to help you get started.

First, you must validate all requests sent to your bot. You must reject invalid requests. The Validator class handles this for you. The applicationPublicKey comes from your application's page on the Discord Developer Portal.

final validator = InteractionValidator(applicationPublicKey: '*****');

final valid = validator.validate(headers: request.headers, body: body);
if (!valid) {
    return Response(401, body: 'invalid request signature');
}

Second, you must respond to ping Interactions with a pong Response

final interaction = Interaction.fromJson(jsonDecode(body));

if (interaction.type == InteractionType.ping) {
    return Response.ok(jsonEncode(InteractionResponse.pong()));
}

If either of these requirements are not met, the Discord Developer Portal will reject your INTERACTIONS ENDPOINT URL

Now you can respond to Application Commands

Discord requires a specially formatted user agent for API calls. The DiscordUserAgent class handles this for you. The url field should point to a useful webpage for your bot. The versionNumber field should match your bot's version number. There is also an optional extra field if you would like to provide additional information about your bot to Discord.

The applicationId and botToken fields come from your application's page on the Discord Developer Portal. If you do not provide a botToken, you must provide a credentialsToken instead.

final api = DiscordApi(
  applicationId: '*****',
  userAgent: DiscordUserAgent(
    url: '*****',
    versionNumber: '*****',
  ),
  botToken: '*****',
);

await api.interactions.createInteractionResponse(
    interaction.id,
    token: interaction.token,
    response:
        InteractionResponse.message(content: 'Hello, Discord Interactions!'),
);

Additional information

This package is very much in-progress. If you have any suggestions or feedback, please open an issue on GitHub.

You might also like...

Figma API client written in pure Dart

figma A library for interacting with Figma APIs. Created from templates made available by Stagehand under a BSD-style license. Usage A simple usage ex

Oct 19, 2022

Simple Chat Application using pure Firebase.

chat_app A new Flutter project. Getting Started This project is a starting point for a Flutter application. A few resources to get you started if this

Dec 29, 2021

Math rendering and editing in pure Flutter.

Math rendering and editing in pure Flutter.

Flutter Math Math equation rendering in pure Dart & Flutter. This project aims to achieve maximum compatibility and fidelity with regard to the KaTeX

Dec 16, 2022

Real-Distributed RTC System by pure Go and Flutter

ION ION is a distributed real-time communication system, the goal is to chat anydevice, anytime, anywhere! Online Docs https://pionion.github.io Spons

Jan 8, 2023

UI design for mobile, create using visual studio code & flutter dart programming languange

HCIProjectLab A new Flutter project. Getting Started This project is a starting point for a Flutter application. A few resources to get you started if

Oct 13, 2021

Actor model implementation in Dart. This package makes it easier to work with isolates, create clusters of isolates.

Actor model implementation in Dart. This package makes it easier to work with isolates, create clusters of isolates.

Actor model implementation in Dart Languages: Introduction About Theater Installing What is Actor Notes about the actors Actor system Actor tree Using

Nov 14, 2022

Create mobile file manager design using Flutter

Create mobile file manager design using Flutter

Mobile File Manager Watch it on YouTube Home & Cloud Screen On this file manager design has two pages. The Home page displays file usage information,

Dec 23, 2022

A shopping cart application that lets the user create an account, select items, save the items in the cart, pay using the payment gateway, change account details and check order history.

Shopping Cart A new Flutter application. The main code file has all the code required for the mobile application. Getting Started This project is a st

Oct 14, 2021

Developed a Group chat application using Flutter and Firebase, where users can register and create groups or join already existing groups and start conversing with each other.

Developed a Group chat application using Flutter and Firebase, where users can register and create groups or join already existing groups and start conversing with each other.

GroupChatApp About Developed a Group chat application using Flutter and Firebase, where users can register and create groups or join already existing

Dec 1, 2022
Dot-Net-Inverview-Bot - Dot net interview questions answering by bot built with flutter

Dot Net Interview question Answering Bot Dot net interview questions answering b

Maddi Mahesh 5 Feb 2, 2022
A web dashboard that allows you to monitor your Chia farm and sends notifications when blocks are found and new plots are completed through a discord bot. It can link multiple farmers/harvesters to your account.

farmr A web dashboard that allows you to monitor your Chia farm and sends notifications when blocks are found and new plots are completed through a di

Gil Nobrega 261 Jan 2, 2023
A task manager built with Flutter, Serverless, Postgres, Firebase

Tasky Mobile App A project management mobile app This project is an implementation of a Design i found on uigaints.com by Ashish Dhakal. The Backend w

Etornam Sunu 137 Dec 31, 2022
Interactions subpackage for nyxx_library

nyxx_interactions Simple, robust framework for creating discord bots for Dart language. Features Slash commands support Supports and provides easy API

nyxx - discord api for dart 7 Nov 20, 2022
Test telegram bot written in dart using teledart package

Dart-Tg-Bot Test telegram bot written in dart using teledart package. Run on local machine First install dart Clone the bot's source and install depen

I'm Not A Bot #Left_TG 8 Oct 31, 2022
This is a bot built with Dart lang which helps you people a simple task and have fun

TeleBot This is a bot built with Dart lang which helps you people a simple task and have fun Command supported /jokes - get a random joke ?? /insult -

Rexford Asamoah 10 Oct 25, 2022
A bot to swap instantly tokens using PancakeSwap smart contracts

Swap Pancake Bot Swap Pancake Bot foi feito para fazer swaps instantâneos sem ne

Lucas Almeida 5 Jan 6, 2022
Simple "ping-pong" bot for Anonchat.

Anonchat pingbot A proof-of-concept "ping-pong" bot made for anonchat-v2. Setup The bot can be configured by changing some variables in bot.py, the na

Calamity 2 Feb 5, 2022
Feature-rich and easy-to-use Minecraft Fallout server bot.

更好的 Minecraft 廢土伺服器機器人 ?? 介紹 這是個具有許多功能的廢土機器人,且完全免費與開源 另一大特色就是具有容易操作的界面,而不是傳統的小黑窗,讓任何人都能夠輕鬆使用~ 詳細功能請看 這裡 祝您使用愉快! 立即下載 ?? 下載 本軟體支援 Windows、Linux、macOS 作

菘菘 9 Dec 23, 2022
Encord's cross-platform chat app similar to Discord

Encord-Chat Encord's cross-platform chat app similar to Discord Getting Started This project is a starting point for a Flutter application. A few reso

Black Eagle Strike Force 1 May 17, 2022