Discord Flows

Discord Integration for [Flows.network](https://test.flows.network)

Quick Start

There is a echo bot, but plain text:

```rust use discordflows::{getclient, listentoevent, model::Message};

[no_mangle]

[tokio::main(flavor = "current_thread")]

pub async fn run() { let token = std::env::var("DISCORD_TOKEN").unwrap();

listen_to_event(token.clone(), move |msg| handle(msg, token)).await;

}

async fn handle(msg: Message, token: String) { let client = getclient(token); let channelid = msg.channel_id; let content = msg.content;

if msg.author.bot {
    return;
}

_ = client
    .send_message(
        channel_id.into(),
        &serde_json::json!({
            "content": content,
        }),
    )
    .await;

} ```

[get_client()] is a Discord constructor that represents a bot. If you don't have a token, please see this section.

[listentoevent()] is responsible for registering a listener for the bot represented by the bot_token. When a new Message coming, the callback is called with received Message.

Creating a Bot Account

The following is excerpted from discord.py docs

  1. Make sure you’re logged on to the Discord website.
  2. Navigate to the application page.
  3. Click on the “New Application” button. new-application
  4. Give the application a name and click “Create”. fill-name
  5. Navigate to the “Bot”.
  6. Make sure that Public Bot is ticked if you want others to invite your bot.
  7. Click on the "Reset Token" button. reset-token
  8. Confirm reset by clicking "Yes, do it!" button. confirm-reset-token
  9. Copy the token using the “Copy” button. > It should be worth noting that this token is essentially your bot’s password. > You should never share this with someone else. > In doing so, someone can log in to your bot and do malicious things, > such as leaving servers, ban all members inside a server, > or pinging everyone maliciously. > > The possibilities are endless, so do not share this token. > > If you accidentally leaked your token, > click the “Regenerate” button as soon as possible. > This revokes your old token and re-generates a new one. > Now you need to use the new token to login.
  10. Keep your token in a safe place, the token will only be shown once.

Inviting Your Bot

So you’ve made a Bot User but it’s not actually in any server.

If you want to invite your bot you must create an invite URL for it.

  1. Make sure you’re logged on to the Discord website.
  2. Navigate to the application page
  3. Click on your bot’s page.
  4. Go to the “OAuth2” tab. discord_oauth2
  5. Tick the “bot” checkbox under “scopes”. discord<em>oauth2</em>scope
  6. Tick the permissions required for your bot to function under “Bot Permissions”.
  7. Now the resulting URL can be used to add your bot to a server. Copy and paste the URL into your browser, choose a server to invite the bot to, and click “Authorize”.

The person adding the bot needs “Manage Server” permissions to do so.