Discord Custom Module

discord
#1

I am working on teaching myself how to make a custom module for the Discord portion of the bot. I used the module example as a base as that function will plan well into what I am planning for generating random seeds. I was able to get the twitch part working first then tried to change it to work with discord. I see the file getting loaded and enabled, but when I do !randomstring # I do not see any errors or attempts at calling the custom module.

The particular script I put onto github here:

Any thoughts on what I am missing in the code to work with discord?

Thanks!

#2

Yes, you have just one small mistake that I noticed:

            $.discord.say("Random string: " + getRandomString(parseInt(args[0])));

The first argument is the channel to send to, in this case you are already pulling it back:

            $.discord.say(channel, "Random string: " + getRandomString(parseInt(args[0])));

There may be other problems, I didn’t test the script or really read through the whole thing, but that stood out at me.

Cheers

#3

Oh dang, I failed to update the github page. I made that change and still am not able to to call randomstring.

PS. Just updated the page with that small change.

#4

I installed your script into my test bot in the scripts/discord/commands directory and it seems to work:

image

[05-03-2019 @ 22:38:57.833 MDT] [DISCORD] [#bottest] illusionaryone: !randomstring 10
[05-03-2019 @ 22:38:57.835 MDT] [DISCORD] [#bottest] [CHAT] Random string: lxrbxycddp
[05-03-2019 @ 22:39:14.479 MDT] [DISCORD] [#bottest] illusionaryone: !randomstring 10
[05-03-2019 @ 22:39:14.480 MDT] [DISCORD] [#bottest] [CHAT] Random string: ylpdxsrpfm

You could verify that the script is enabled. Perhaps it isn’t, although my bot automatically enables scripts that I add, maybe because I am in development mode, I cannot remember.

#5

To help speed up debugging and testing, there is an option you can use in botlogin.txt:
reloadscripts=true

Be careful though, some scripts with timers do not get along very well with that. Some scripts do not like being reloaded, especially the core and the customCommands scripts.

#6

I temporarily moved the bot to my local PC so I don’t have a problem rebooting the bot. I found out the script is working correctly for the discord admins only.

image

Do I have the permissions set correctly on this line?

$.discord.registerCommand(’./discord/commands/seed.js’, ‘randomstring’, 0);

#7

0 is everyone, 1 is administrator. That should be fine. I use 0 on other commands that I have written.

Are other commands that are non-admin working properly for non-admins?

#8

Yeah, all other non admin commands do work properly. This is the only one (and only custom script) I run that does not work properly for non-admins.

#9

I have a hypothesis. Can you run !permcom on the command and set it to 0? Then try. I noticed if I set it to 1 in the script once (after clearing my DB entry) and then set to 0 it doesn’t update (which is expected behavior).

#10

Yeah that corrected it. I can now run the command as a non admin. I really appreciate the help!

1 Like
#11

Glad my guess was right! Congrats on your first script!

#12

Thanks! I am glad to be learning off the example script. Thoughts on why the 0 was ignored to start? Fortunately the discord admins of that server are nice enough to help me out with admin commands when needed when I can’t run them from the admin panel.

#13

Did you have it to set 1 perhaps? I installed your script and it was always 0. I was guessing that at some point had it 1 and was left there.

#14

I did flip back and forth for a bit when trying to see if it would make a difference. It originally was 7 when starting out from the baseline twitch script. I would settle on 0 though even after flipping it around.

#15

So, my guess is, some non-0 value was in the DB.

So, the reason why the script doesn’t change it back is we assume that !permcom will set a value and we do not want to overwrite it again with the value from the script for that reason. We also cannot really tell if the value was original or set via permcom (we choose not to track that, need another database table or flag, and not worth the storage really).

Cheers

#16

Ok, I think I understand why it remained that way then. Thank you for the help!

1 Like