SpaceManiac / discord-rs

Rust library for the Discord chat client API
MIT License
390 stars 94 forks source link

User token can receive messages but not send #108

Open stackoverflowin opened 7 years ago

stackoverflowin commented 7 years ago

I seem to be getting this when doing RUST_BACKTRACE=1 cargo run --verbose. I've created a new project, everything seems to be OK in regards to the structure of the project and the configuration. If I don't include the Discord crate it'll compile fine. I'm using the code from the example (https://github.com/SpaceManiac/discord-rs/blob/master/examples/basic_chatbot.rs). It's compiling fine, its just when I run it it throws the panic.

This is my stack-trace: ` Running target/debug/discord_bot thread 'main' panicked at 'Expected token: NotPresent', /buildslave/rust-buildbot/slave/stable-dist-rustc-linux/build/src/libcore/result.rs:837 stack backtrace: 1: 0x556ed6643e6a - std::sys::imp::backtrace::tracing::imp::write::h3188f035833a2635 at /buildslave/rust-buildbot/slave/stable-dist-rustc-linux/build/src/libstd/sys/unix/backtrace/tracing/gcc_s.rs:42 2: 0x556ed664707f - std::panicking::default_hook::{{closure}}::h6385b6959a2dd25b at /buildslave/rust-buildbot/slave/stable-dist-rustc-linux/build/src/libstd/panicking.rs:349 3: 0x556ed6646c7e - std::panicking::default_hook::he4f3b61755d7fa95 at /buildslave/rust-buildbot/slave/stable-dist-rustc-linux/build/src/libstd/panicking.rs:365 4: 0x556ed6647527 - std::panicking::rust_panic_with_hook::hf00b8130f73095ec at /buildslave/rust-buildbot/slave/stable-dist-rustc-linux/build/src/libstd/panicking.rs:553 5: 0x556ed6647364 - std::panicking::begin_panic::h6227f62cb2cdaeb4 at /buildslave/rust-buildbot/slave/stable-dist-rustc-linux/build/src/libstd/panicking.rs:515 6: 0x556ed66472d9 - std::panicking::begin_panic_fmt::h173eadd80ae64bec at /buildslave/rust-buildbot/slave/stable-dist-rustc-linux/build/src/libstd/panicking.rs:499 7: 0x556ed6647267 - rust_begin_unwind at /buildslave/rust-buildbot/slave/stable-dist-rustc-linux/build/src/libstd/panicking.rs:475 8: 0x556ed666e27d - core::panicking::panic_fmt::h3b2d1e30090844ff at /buildslave/rust-buildbot/slave/stable-dist-rustc-linux/build/src/libcore/panicking.rs:69 9: 0x556ed6295604 - core::result::unwrap_failed::h7badae956541c245 at /buildslave/rust-buildbot/slave/stable-dist-rustc-linux/build/src/libcore/macros.rs:29 10: 0x556ed628d61d - <core::result::Result<T, E>>::expect::hf25aa47c10d0d94e at /buildslave/rust-buildbot/slave/stable-dist-rustc-linux/build/src/libcore/result.rs:761 11: 0x556ed62a6dee - discord_bot::main::h03a45e76d75fb610 at /home/god/Documents/Rust/discord_bot/src/main.rs:10 12: 0x556ed664e51a - __rust_maybe_catch_panic at /buildslave/rust-buildbot/slave/stable-dist-rustc-linux/build/src/libpanic_unwind/lib.rs:98 13: 0x556ed6647c66 - std::rt::lang_start::h65647f6e36cffdae at /buildslave/rust-buildbot/slave/stable-dist-rustc-linux/build/src/libstd/panicking.rs:434 at /buildslave/rust-buildbot/slave/stable-dist-rustc-linux/build/src/libstd/panic.rs:351 at /buildslave/rust-buildbot/slave/stable-dist-rustc-linux/build/src/libstd/rt.rs:57 14: 0x556ed62a79c2 - main 15: 0x7f5d3f5f482f - __libc_start_main 16: 0x556ed6281468 - _start 17: 0x0 -

`

I'm having a feeling this is something to do with package versions clashing?

ghost commented 7 years ago

Are you on Windows?

stackoverflowin commented 7 years ago

No, I'm on Ubuntu. All of my packages are installed that I need, not sure what's going on.

SpaceManiac commented 7 years ago

thread 'main' panicked at 'Expected token: NotPresent' src/main.rs:10 &env::var("DISCORD_TOKEN").expect("Expected token"),

Set DISCORD_TOKEN in your environment, or change the code to discover the token some other way.

stackoverflowin commented 7 years ago

OK, I'm now having the issue that messages are not being sent. I'm still using the example code, when I send '!test' it's not replying or anything. Messages are being recieved just fine.

SpaceManiac commented 7 years ago

Are you sure the bot has permission to send messages in the relevant channel? Try changing line 21, let _ = (...);, to (...).unwrap(); to see the error message.

stackoverflowin commented 7 years ago

Yes, I'm getting this now:

thread 'main' panicked at 'calledResult::unwrap()on anErrvalue: Status(Unauthorized, Some({"code":0,"message":"401: Unauthorized"}))', /buildslave/rust-buildbot/slave/stable-dist-rustc-linux/build/src/libcore/result.rs:868

Although I can send messages through the Discord web client just fine on this channel.

SpaceManiac commented 7 years ago

It may be that you can send messages, but have you checked the permissions for the bot? Unauthorized usually indicates this.

stackoverflowin commented 7 years ago

Yes, I'm using the token from the account I'm sending messages on/receiving which is my personal account.

SpaceManiac commented 7 years ago

The example code uses from_bot_token. You need to supply it a bot token (create here), or use from_user_token for a user token.

stackoverflowin commented 7 years ago

Yes, I'm already doing that. The messages are being received fine but I can't send at all.

SpaceManiac commented 7 years ago

Works for me. You're sure the token is freshly extracted from the Discord client, and for the right user? Do you have 2FA enabled?