forked from serenity-rs/poise
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.rs
123 lines (116 loc) · 4.25 KB
/
main.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
mod attachment_parameter;
mod autocomplete;
mod bool_parameter;
mod builtins;
mod checks;
mod choice_parameter;
mod code_block_parameter;
mod collector;
mod context_menu;
mod inherit_checks;
mod localization;
mod modal;
mod paginate;
mod panic_handler;
mod parameter_attributes;
mod raw_identifiers;
mod response_with_reply;
mod subcommand_required;
mod subcommands;
mod track_edits;
use poise::serenity_prelude as serenity;
type Error = Box<dyn std::error::Error + Send + Sync>;
type Context<'a> = poise::Context<'a, Data, Error>;
// User data, which is stored and accessible in all command invocations
pub struct Data {}
#[tokio::main]
async fn main() {
env_logger::init();
let framework = poise::Framework::builder()
.options(poise::FrameworkOptions {
commands: vec![
attachment_parameter::file_details(),
attachment_parameter::totalsize(),
autocomplete::greet(),
bool_parameter::oracle(),
#[cfg(feature = "cache")]
builtins::servers(),
builtins::help(),
builtins::pretty_help(),
checks::shutdown(),
checks::modonly(),
checks::delete(),
checks::ferrisparty(),
checks::cooldowns(),
checks::minmax(),
checks::get_guild_name(),
checks::only_in_dms(),
checks::lennyface(),
checks::permissions_v2(),
choice_parameter::choice(),
choice_parameter::inline_choice(),
choice_parameter::inline_choice_int(),
code_block_parameter::code(),
collector::boop(),
context_menu::user_info(),
context_menu::echo(),
inherit_checks::parent_checks(),
localization::welcome(),
modal::modal(),
modal::component_modal(),
paginate::paginate(),
panic_handler::div(),
parameter_attributes::addmultiple(),
parameter_attributes::voiceinfo(),
parameter_attributes::say(),
parameter_attributes::punish(),
parameter_attributes::stringlen(),
raw_identifiers::r#move(),
response_with_reply::reply(),
subcommands::parent(),
subcommand_required::parent_subcommand_required(),
track_edits::test_reuse_response(),
track_edits::add(),
],
prefix_options: poise::PrefixFrameworkOptions {
prefix: Some("~".into()),
non_command_message: Some(|_, _, msg| {
Box::pin(async move {
println!("non command message!: {}", msg.content);
Ok(())
})
}),
..Default::default()
},
on_error: |error| {
Box::pin(async move {
println!("what the hell");
match error {
poise::FrameworkError::ArgumentParse { error, .. } => {
if let Some(error) = error.downcast_ref::<serenity::RoleParseError>() {
println!("Found a RoleParseError: {:?}", error);
} else {
println!("Not a RoleParseError :(");
}
}
other => poise::builtins::on_error(other).await.unwrap(),
}
})
},
..Default::default()
})
.setup(move |ctx, _ready, framework| {
Box::pin(async move {
poise::builtins::register_globally(ctx, &framework.options().commands).await?;
Ok(Data {})
})
})
.build();
let token = std::env::var("DISCORD_TOKEN").unwrap();
let intents =
serenity::GatewayIntents::non_privileged() | serenity::GatewayIntents::MESSAGE_CONTENT;
let client = serenity::ClientBuilder::new(token, intents)
.framework(framework)
.await;
client.unwrap().start().await.unwrap()
}