Darkside138 / DiscordSoundboard

Java Soundboard for Discord
Apache License 2.0
137 stars 55 forks source link

Entrance command works within server but not through PM #144

Closed bobotran closed 3 years ago

bobotran commented 4 years ago

I used the set entrance sound command in one of the server channels and it worked fine. Attempting to use the same command in my PM with the bot resulted in Entrance command incorrect. Required input is ?entrance <userid/username> <soundfile>

raitono commented 4 years ago

This is caused by this section of the code: https://github.com/Darkside138/DiscordSoundboard/blob/974e71edbd9356875de9dc56367aa62f052c6086/src/main/java/net/dirtydeeds/discordsoundboard/ChatSoundBoardListener.java#L202-L205

The MessageReceivedEvent.getMember() function will be null if received in a private channel (DM): [reference](https://ci.dv8tion.net/job/JDA/javadoc/net/dv8tion/jda/api/events/message/MessageReceivedEvent.html#getMember())

May want to add something that checks what comes back from [event.GetChannelType()](https://ci.dv8tion.net/job/JDA/javadoc/net/dv8tion/jda/api/events/message/GenericMessageEvent.html#getChannelType()) or [event.getPrivateChannel()](https://ci.dv8tion.net/job/JDA/javadoc/net/dv8tion/jda/api/events/message/GenericMessageEvent.html#getPrivateChannel()) and then get the author accordingly.

I would try to do this myself, but I am having significant issues getting the environment set up. I haven't done Java in 10 years and have never used Gradle, so I'm running into problems. Good luck to whoever can get that working!

Darkside138 commented 3 years ago

So, the issue here is that you can't issue admin commands via PM because it doesn't know what guild (server) you are trying to do them to check if you have admin privileges. I could possibly add an optional param that you could specify the server. I'll add it to the list but it's probably going to be low priority.