Coder Social home page Coder Social logo

slashy's Introduction

Slashy

This is a wip command frame work for Serenity that allows commands to be registered for both normal text commands and Discord's new slash commands

Instead of taking Serenity's attribute style of command registering, we register commands via a tree of possible arguments with different subcommands being executed at different branches.

Basic Command

use slashy::{
    command,
    commands::CommandResult,
    framework::{CommandContext, Framework},
    serenity::{prelude::GatewayIntents, Client},
    settings::Settings,
    subcommand,
};

command! {
    ping,
    "ping pong",
    pong,
    [
        optional String text | "text to echo"
    ]
}

#[subcommand]
async fn pong(ctx: &CommandContext) -> CommandResult {
    ctx.send_str(&format!("pong {:?}", ctx.get_arg("text")))
        .await?;
    Ok(())
}

#[tokio::main]
async fn main() {
    let token = std::env::var("DISCORD_TOKEN").expect("token");
    let app_id = std::env::var("APPLICATION_ID")
        .expect("app_id")
        .parse()
        .expect("app_id parse");

    // Create the slashy framework
    let settings = Settings {
        prefixes: vec!["!"],
        auto_register: true,
        auto_delete: true,
        slash_command_guilds: vec![],
    };
    let framework = Framework::new(settings, app_id, token.clone())
        .await
        .command::<PING_COMMAND>();

    // Login with a bot token from the environment
    let mut client = Client::builder(
        token,
        GatewayIntents::GUILD_MESSAGES | GatewayIntents::MESSAGE_CONTENT,
    )
    .event_handler(framework)
    .await
    .expect("Error creating client");

    // start listening for events by starting a single shard
    if let Err(why) = client.start().await {
        println!("An error occurred while running the client: {why:?}");
    }
}

slashy's People

Contributors

maddymakesgames avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Forkers

oxkitsune

slashy's Issues

Build fail

It doesn't build.

 ~/git/random-cat-bot  main ?4 ▓▒░ cargo run                                                                                                                                                         ░▒▓ 101 х  19s
    Blocking waiting for file lock on build directory
   Compiling scopeguard v1.1.0
   Compiling smallvec v1.10.0
   Compiling slashy v0.1.1
error[E0432]: unresolved imports `serenity::model::interactions::ApplicationCommandInteractionDataOption`, `serenity::model::interactions::InteractionData`
 --> /home/alejandra/.cargo/registry/src/github.com-1ecc6299db9ec823/slashy-0.1.1/src/argument.rs:3:87
  |
3 | use serenity::{client::Cache, model::{id::{ChannelId, RoleId, UserId}, interactions::{ApplicationCommandInteractionDataOption as InteractionOption, Interaction, InteractionData}}};
  |                                                                                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^               ^^^^^^^^^^^^^^^ no `InteractionData` in `model::interactions`
  |                                                                                       |
  |                                                                                       no `ApplicationCommandInteractionDataOption` in `model::interactions`
  |
  = help: consider importing this struct instead:
          serenity::model::prelude::application_command::ApplicationCommandInteractionDataOption
help: a similar name exists in the module
  |
3 | use serenity::{client::Cache, model::{id::{ChannelId, RoleId, UserId}, interactions::{ApplicationCommandInteraction as InteractionOption, Interaction, InteractionData}}};
  |                                                                                       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
help: a similar name exists in the module
  |
3 | use serenity::{client::Cache, model::{id::{ChannelId, RoleId, UserId}, interactions::{ApplicationCommandInteractionDataOption as InteractionOption, Interaction, Interaction}}};
  |                                                                                                                                                                  ~~~~~~~~~~~

error[E0432]: unresolved import `serenity::model::interactions::InteractionData`
  --> /home/alejandra/.cargo/registry/src/github.com-1ecc6299db9ec823/slashy-0.1.1/src/framework.rs:17:182
   |
17 | ...GuildId, MessageId, RoleId, UserId}, interactions::{Interaction, InteractionData, InteractionResponseType, InteractionType}, prelude::{CurrentUser, Presence, Ready, User, VoiceState}}};
   |                                                                     ^^^^^^^^^^^^^^^
   |                                                                     |
   |                                                                     no `InteractionData` in `model::interactions`
   |                                                                     help: a similar name exists in the module: `Interaction`

   Compiling lock_api v0.4.9
   Compiling parking_lot_core v0.9.6
error[E0599]: no method named `create_interaction_response` found for reference `&Interaction` in the current scope
   --> /home/alejandra/.cargo/registry/src/github.com-1ecc6299db9ec823/slashy-0.1.1/src/framework.rs:465:19
    |
465 |                 i.create_interaction_response(&self.ctx, |c| {
    |                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^ method not found in `&Interaction`

error[E0599]: no method named `create_interaction_response` found for reference `&Interaction` in the current scope
   --> /home/alejandra/.cargo/registry/src/github.com-1ecc6299db9ec823/slashy-0.1.1/src/framework.rs:500:19
    |
500 |                 i.create_interaction_response(&self.ctx, |c| {
    |                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^ method not found in `&Interaction`

error[E0609]: no field `channel_id` on type `&Interaction`
   --> /home/alejandra/.cargo/registry/src/github.com-1ecc6299db9ec823/slashy-0.1.1/src/framework.rs:528:48
    |
528 |             CommandSource::Interaction(i) => i.channel_id.unwrap().send_message(&self.ctx, f).await,
    |                                                ^^^^^^^^^^

error[E0609]: no field `member` on type `&Interaction`
   --> /home/alejandra/.cargo/registry/src/github.com-1ecc6299db9ec823/slashy-0.1.1/src/framework.rs:536:48
    |
536 |             CommandSource::Interaction(i) => i.member.clone().ok_or(serenity::Error::Other("No member on interaction")),
    |                                                ^^^^^^

error[E0609]: no field `guild_id` on type `&Interaction`
   --> /home/alejandra/.cargo/registry/src/github.com-1ecc6299db9ec823/slashy-0.1.1/src/framework.rs:544:54
    |
544 |             CommandSource::Interaction(i) => match i.guild_id {
    |                                                      ^^^^^^^^

error[E0609]: no field `channel_id` on type `&Interaction`
   --> /home/alejandra/.cargo/registry/src/github.com-1ecc6299db9ec823/slashy-0.1.1/src/framework.rs:566:48
    |
566 |             CommandSource::Interaction(i) => i.channel_id.unwrap().to_channel(&self.ctx).await,
    |                                                ^^^^^^^^^^

error[E0609]: no field `data` on type `&Interaction`
   --> /home/alejandra/.cargo/registry/src/github.com-1ecc6299db9ec823/slashy-0.1.1/src/argument.rs:210:38
    |
210 |         let data = match interaction.data.clone().unwrap() {
    |                                      ^^^^

   Compiling dashmap v5.4.0
   Compiling parking_lot v0.12.1
error[E0615]: attempted to take value of method `kind` on type `Interaction`
   --> /home/alejandra/.cargo/registry/src/github.com-1ecc6299db9ec823/slashy-0.1.1/src/framework.rs:323:24
    |
323 |         if interaction.kind != InteractionType::ApplicationCommand {
    |                        ^^^^ method, not a field
    |
help: use parentheses to call the method
    |
323 |         if interaction.kind() != InteractionType::ApplicationCommand {
    |                            ++

error[E0609]: no field `data` on type `Interaction`
   --> /home/alejandra/.cargo/registry/src/github.com-1ecc6299db9ec823/slashy-0.1.1/src/framework.rs:327:39
    |
327 |         let name = match &interaction.data {
    |                                       ^^^^

error[E0609]: no field `channel_id` on type `Interaction`
   --> /home/alejandra/.cargo/registry/src/github.com-1ecc6299db9ec823/slashy-0.1.1/src/framework.rs:358:38
    |
358 | ...                   .channel_id
    |                        ^^^^^^^^^^

error[E0609]: no field `channel_id` on type `Interaction`
   --> /home/alejandra/.cargo/registry/src/github.com-1ecc6299db9ec823/slashy-0.1.1/src/framework.rs:370:30
    |
370 | ...                   .channel_id
    |                        ^^^^^^^^^^

error[E0609]: no field `member` on type `&Interaction`
   --> /home/alejandra/.cargo/registry/src/github.com-1ecc6299db9ec823/slashy-0.1.1/src/framework.rs:456:48
    |
456 |             CommandSource::Interaction(i) => i.member.clone().map(|m| m.user),
    |                                                ^^^^^^

error[E0609]: no field `guild_id` on type `&Interaction`
   --> /home/alejandra/.cargo/registry/src/github.com-1ecc6299db9ec823/slashy-0.1.1/src/framework.rs:558:48
    |
558 |             CommandSource::Interaction(i) => i.guild_id,
    |                                                ^^^^^^^^

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.