Slash commands are cool
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

27 lines
994B

  1. use crate::discord;
  2. use crate::discord::{Interaction, InteractionResponse, InteractionApplicationCommandCallbackData};
  3. // fn foo() -> (definition, private?)
  4. // hello-world data for telling Discord about it
  5. pub fn def_hello_world() -> (discord::ApplicationCommand, Option<String>) {
  6. (discord::ApplicationCommand {
  7. id: None,
  8. application_id: None,
  9. name: "hello-world".to_string(),
  10. description: "Hello World".to_string(),
  11. options: None,
  12. }, Some("616329232389505055".to_string()))
  13. }
  14. // hello-world action when someone uses the command on Discord
  15. pub fn hello_world(interaction: &Interaction) -> InteractionResponse {
  16. let cmd = interaction.cmd().unwrap();
  17. InteractionResponse::ChannelMessage {
  18. data: Some(InteractionApplicationCommandCallbackData {
  19. tts: false,
  20. content: format!("Hello {}!", cmd.member.nick.unwrap_or(cmd.member.user.unwrap().username)),
  21. allowed_mentions: None,
  22. }),
  23. }
  24. }