Copied from sardonicism-04/discord-rich-presence
access_token
Simple demo of how to use this
```rust use discord_ipc::{ models::commands::*, Command, DiscordIpc, DiscordIpcClient, Event, EventReceive, };
// get all messages from the client fn handlemessage(event: EventReceive) { if let EventReceive::CommandReturn(eventtype) = event { match eventtype { BasedCommandReturn::GetSelectedVoiceChannel { data } => { println!("{:#?}", data.guildid);
for user in data.voice_states.iter() {
println!("{}", user.nick);
}
}
BasedCommandReturn::SelectVoiceChannel { .. } => todo!(),
_ => {
println!("{:#?}", event_type);
}
}
} else if let EventReceive::Event(eventtype) = event { println!("Evt {:#?}", eventtype); } }
async fn main() { // load env vars dotenv::dotenv().ok();
// access token from env let accesstoken = dotenv::var("ACCESSTOKEN").unwrap();
// client id from env let clientid = dotenv::var("CLIENTID").unwrap();
// connect to discord client with overlayed id let mut client = DiscordIpcClient::new(&client_id) .await .expect("Client failed to connect");
// login to the client client.login(access_token).await.unwrap();
// test join a voice channel client .emit(Command::getselectedvoice_channel()) .await .ok();
client .emit(Event::speakingstartevent("1022132922565804062")) .await .ok();
client .emit(Event::speakingstopevent("1022132922565804062")) .await .ok();
// sub to all events to via this listener client.handler(handle_message).await.ok(); } ```
Make sure to add an .env
file with a valid access token and client id.
ACCESS_TOKEN="dank_meme"
CLIENT_ID="42069420"
make
or carco run
to run the main file
https://github.com/sardonicism-04/discord-rich-presence https://gitlab.com/valeth/discord-rpc-client.rs https://github.com/ldesgoui/discordgamesdk https://github.com/jewlexx/discord-presence
https://discord.com/developers/docs/topics/rpc