Jump to content

VSChatBot - A Discord bot integration for VS servers


Recommended Posts

VSChatBot

Here's a Discord Bot for those of you who want to engage your community more by allowing them to see what goes on in-game, all from the safety of their favourite chat application, Discord!
I've been developing it in cooperation with the awesome community of RabbitTech, so a big shout-out to those guys (especially TechRabbit himself) for dealing with the silly bugs and giving feedback. 

Features

  • Send text messages from the General chat in-game, directly to a discord channel 
  • Send messages from the same Discord channel, directly to the General chat in-game 
  • Assuming storms are enabled, storm notifications will be sent when they approach, begin and end
  • Optional death messages
  • Optional server up/down messages
  • Various utility commands like !help, !time, !players and !lastseen

Installation

It's a discord client wrapped as a regular mod, so installing it is like any other regular VS server-side mod. 
You will, however, have to manually create a bot at https://discord.com/developers/applications

  1. Create a new application and name it something appropriate
  2. Go into the Bot tab and 'Add Bot'
  3. Optionally disallow 'public bot' which seems to be the default
  4. Go into the OAuth2 tab
  5. Scroll down and give it the 'bot' scope
  6. Scroll further down after clicking and add the 'send messages' text permission
  7. Scroll up again and copy the link that Discord has generated into a new browser window
  8. Add it to the respective server you want
  9. You should now see a bot connect to your Discord server
  10. Go back to the Bot tab and keep it open for when you need to copy your Bot token into the config file

Once this is done, you can take the vschatbot.zip and put into your mods folder.
On the first start-up, the mod will create a vschatbot.json config file in your ModConfig folder and then shut down. This needs to be filled otherwise the bot will not function.

The 3 mandatory fields are:

  • "Token" which is the token generated by the Discord application. Must be a string, so surrounded by "".
  • "ServerId" which is the id of the discord server you want it to connect to. Make sure this remains a number (so no "")!
  • "ChannelId" which is the id of the channel on the discord server you want it to send messages from in-game to, and take from. Make sure this remains a number!

ServerId and ChannelId are the identifiers given by Discord to your server and channel. You can find them directly in Discord if you enable developer mode and then right click -> 'copy id'.

Once these are filled, you can restart the server and you should see the following message as part of start-up in server-main.txt in your log files:

[Notification] vschatbot: connected to discord and ready!

If not, something went wrong, most likely during configuration of the Discord bot.

Commands

The bot have several commands available, but all are out-of-game. They can be triggered by prefixing your message with ! or @mentioning the bot

  • !help [string] - shows all the available commands if sent with no arguments. If sent with argument, will show the command help of that particular command.
  • !players - shows all online players at the time
  • !time - shows the current time of the server and the current season. The time of the server respects the server config of additional days per month and more, so you will see dates like 35. March. This is to be expected and is how the game calendar works.
  • !lastseen [playername] - allows you to look up when the given playername was last seen online (only works after the bot has been installed obviously).
  • !stats [playername] - shows more detailed stats for an individual (only total play time + deaths atm, more coming as I develop my player stats mod)

Source Code:
https://gitlab.com/vsmods-public/vschatbot

Releases:
v1.1.1 (03/01/2020): https://gitlab.com/vsmods-public/vschatbot/-/releases/1.1.1

 

Edited by Capsup
  • Like 4
  • Amazing! 2
Link to post
Share on other sites
14 minutes ago, Kai Effelsberg said:

Featured on "Vintage Story Online: Conquest of Blocks" (https://Discord.io/vintagestoryonline). Exactly what we where looking for for some time already. Thank you.

Glad you like it! We spent a couple weeks working on it and testing it out. Really changed how close the community is on the RabbitTech server

Link to post
Share on other sites
On 11/23/2020 at 9:16 AM, Julius van Vern said:

Thanks for this great mod. He works perfectly. But on more please. Only 3 seconds per user, was send from the Bot. This should be manually adjustable or reduced to 2 seconds. Is it possible? Thank you :)

Hey, glad to hear it works for you!

I'm not entirely sure what you're asking though? I can't think of anything that only happens every x seconds, could you elaborate a little bit on what that might be? I'm not entirely sure what it is you want made configurable.

On 11/23/2020 at 2:53 PM, Digitalr said:

Bot not sends messages about temporal storms. Game chat, server start/stop, player login/disconnect - all OK.

Storm notifications enabled in config.

 

Hit me up on Discord at Capsup#8250 and we can try to debug it together, if you're interested. It works for others. :)

Edited by Capsup
Link to post
Share on other sites

Updated the OP with some more information about the commands that the bot makes available. I don't believe I've mentioned these anywhere except for people asking directly. It still works with v1.14.2

Still interested in hearing about feedback and feature requests. We have only encountered the bot becoming sort of unstable, once, on the RabbitTech server, but a simple restart of the server fixed it. I've seen it running on a few servers, and so far I haven't heard of any bugs encountered. The two posters from above never got back to me, so I'm not sure if they managed to fix their issues.

Link to post
Share on other sites
3 hours ago, Sypher Tendervine said:

Hey caps, is there any documentation for variable handlers like {strength}? If I deleted it in my config I totally would've forgotten it was there. 😧

Hey Sypher,

I haven't had any requests for this sort of functionality, so I just added this on a whim last time when releasing. So there is only that one replacement.

  • Like 1
Link to post
Share on other sites
12:54:31 [Server Notification] Entering runphase LoadGame
Version: ??????????????? ?????? artEA#8001 v1.14.0 (Stable)01/10/2021 12:54:31: Critical error occurred
System.NullReferenceException: Object reference not set to an instance of an object
  at DSharpPlus.DiscordClient.SendMessageAsync (DSharpPlus.Entities.DiscordChannel channel, System.String content, System.Boolean tts, DSharpPlus.Entities.DiscordEmbed embed) [0x00006] in <73bf8d85ff3e42158583ab7e0be5fd9f>:0
  at vschatbot.src.DiscordWatcher.sendDiscordMessage (System.String message, DSharpPlus.Entities.DiscordEmbed embed) [0x00001] in <0dd8f803229d46d8922633b2f9b3fa75>:0
  at vschatbot.src.DiscordWatcher.Event_ServerStartup () [0x0000d] in <0dd8f803229d46d8922633b2f9b3fa75>:0
  at Vintagestory.Server.ServerEventAPI.OnServerStage (Vintagestory.API.Server.EnumServerRunPhase runPhase) [0x00025] in <785327a3fe2e4d2ebe5e223bef6e3faa>:0
  at Vintagestory.Server.ServerSystemModHandler.OnBeginGameReady (_wTXE2v1LflyYDnwkuDFOLi4HPJm savegame) [0x00000] in <785327a3fe2e4d2ebe5e223bef6e3faa>:0
  at Vintagestory.Server.ServerMain.EnterRunPhase (Vintagestory.API.Server.EnumServerRunPhase runPhase) [0x0009a] in <785327a3fe2e4d2ebe5e223bef6e3faa>:0
  at Vintagestory.Server.ServerMain.Launch () [0x002b4] in <785327a3fe2e4d2ebe5e223bef6e3faa>:0
  at ?????????????????????????????????????????.????????????????????????????????????????? () [0x000ce] in <46462d398d354fd8929b482784f4efa0>:0
  at _eVFDVqwXngafMmcD9boVPO86iWx._hbMghNVJIKTGI5zBx3SuxRG1XDI (System.Threading.ThreadStart ) [0x00007] in <785327a3fe2e4d2ebe5e223bef6e3faa>:0
-------------------------------
Crash written to file at "/home/server/data/Logs/server-crash.txt"

Unhandled Exception occurred
Version: ??????????????? ?????? artEA#8001 v1.14.0 (Stable)01/10/2021 12:54:42: Critical error occurred
System.NullReferenceException: Object reference not set to an instance of an object
  at DSharpPlus.DiscordClient.Dispose () [0x00056] in <73bf8d85ff3e42158583ab7e0be5fd9f>:0
  at DSharpPlus.DiscordClient.Finalize () [0x00000] in <73bf8d85ff3e42158583ab7e0be5fd9f>:0
-------------------------------
Crash written to file at "/home/server/data/Logs/client-crash.txt"

[ERROR] FATAL UNHANDLED EXCEPTION: System.NullReferenceException: Object reference not set to an instance of an object
  at DSharpPlus.DiscordClient.Dispose () [0x00056] in <73bf8d85ff3e42158583ab7e0be5fd9f>:0
  at DSharpPlus.DiscordClient.Finalize () [0x00000] in <73bf8d85ff3e42158583ab7e0be5fd9f>:0
Unknown command line option: '--arch=32'

 

:((

Link to post
Share on other sites
2 hours ago, momai Alex said:

12:54:31 [Server Notification] Entering runphase LoadGame
Version: ??????????????? ?????? artEA#8001 v1.14.0 (Stable)01/10/2021 12:54:31: Critical error occurred
System.NullReferenceException: Object reference not set to an instance of an object
  at DSharpPlus.DiscordClient.SendMessageAsync (DSharpPlus.Entities.DiscordChannel channel, System.String content, System.Boolean tts, DSharpPlus.Entities.DiscordEmbed embed) [0x00006] in <73bf8d85ff3e42158583ab7e0be5fd9f>:0
  at vschatbot.src.DiscordWatcher.sendDiscordMessage (System.String message, DSharpPlus.Entities.DiscordEmbed embed) [0x00001] in <0dd8f803229d46d8922633b2f9b3fa75>:0
  at vschatbot.src.DiscordWatcher.Event_ServerStartup () [0x0000d] in <0dd8f803229d46d8922633b2f9b3fa75>:0
  at Vintagestory.Server.ServerEventAPI.OnServerStage (Vintagestory.API.Server.EnumServerRunPhase runPhase) [0x00025] in <785327a3fe2e4d2ebe5e223bef6e3faa>:0
  at Vintagestory.Server.ServerSystemModHandler.OnBeginGameReady (_wTXE2v1LflyYDnwkuDFOLi4HPJm savegame) [0x00000] in <785327a3fe2e4d2ebe5e223bef6e3faa>:0
  at Vintagestory.Server.ServerMain.EnterRunPhase (Vintagestory.API.Server.EnumServerRunPhase runPhase) [0x0009a] in <785327a3fe2e4d2ebe5e223bef6e3faa>:0
  at Vintagestory.Server.ServerMain.Launch () [0x002b4] in <785327a3fe2e4d2ebe5e223bef6e3faa>:0
  at ?????????????????????????????????????????.????????????????????????????????????????? () [0x000ce] in <46462d398d354fd8929b482784f4efa0>:0
  at _eVFDVqwXngafMmcD9boVPO86iWx._hbMghNVJIKTGI5zBx3SuxRG1XDI (System.Threading.ThreadStart ) [0x00007] in <785327a3fe2e4d2ebe5e223bef6e3faa>:0
-------------------------------
Crash written to file at "/home/server/data/Logs/server-crash.txt"

Unhandled Exception occurred
Version: ??????????????? ?????? artEA#8001 v1.14.0 (Stable)01/10/2021 12:54:42: Critical error occurred
System.NullReferenceException: Object reference not set to an instance of an object
  at DSharpPlus.DiscordClient.Dispose () [0x00056] in <73bf8d85ff3e42158583ab7e0be5fd9f>:0
  at DSharpPlus.DiscordClient.Finalize () [0x00000] in <73bf8d85ff3e42158583ab7e0be5fd9f>:0
-------------------------------
Crash written to file at "/home/server/data/Logs/client-crash.txt"

[ERROR] FATAL UNHANDLED EXCEPTION: System.NullReferenceException: Object reference not set to an instance of an object
  at DSharpPlus.DiscordClient.Dispose () [0x00056] in <73bf8d85ff3e42158583ab7e0be5fd9f>:0
  at DSharpPlus.DiscordClient.Finalize () [0x00000] in <73bf8d85ff3e42158583ab7e0be5fd9f>:0
Unknown command line option: '--arch=32'

 

:((

 

I'm assuming you don't see the message 

[Notification] vschatbot: connected to discord and ready!

before that error?
In that case, is your configuration actually correct?

Also, I think a race condition can occur here if your network is too slow in comparison to server startup, the VS server itself will attempt to send a 'ready' message to Discord before the bot has actually connected. Anyways, I added a simple check so it just discards the message at that point. Will be included in the next release.

Link to post
Share on other sites

The server worked and then crashed. And all the following times did not rise until I removed the mod. I tried to redo the configuration, reissued the token. And Installed a new version of the mod. Crash anyway
Very surprisingly it crashed on a running server. Those. the mod was working and suddenly stopped.

Link to post
Share on other sites

Created a new discord bot. Issued permission to read messages. Added to the server. Mod loads without config. With the config, this is such a crash

 

artEA#8001 v1.14.0 (Stable)01/14/2021 11:22:59: Critical error occurred
System.NullReferenceException: Object reference not set to an instance of an object
  at DSharpPlus.DiscordClient.SendMessageAsync (DSharpPlus.Entities.DiscordChannel channel, System.String content, System.Boolean tts, DSharpPlus.Entities.DiscordEmbed embed) [0x00006] in <73bf8d85ff3e42158583ab7e0be5fd9f>:0
  at vschatbot.src.DiscordWatcher.sendDiscordMessage (System.String message, DSharpPlus.Entities.DiscordEmbed embed) [0x00001] in <0dd8f803229d46d8922633b2f9b3fa75>:0
  at vschatbot.src.DiscordWatcher.Event_ServerStartup () [0x0000d] in <0dd8f803229d46d8922633b2f9b3fa75>:0
  at Vintagestory.Server.ServerEventAPI.OnServerStage (Vintagestory.API.Server.EnumServerRunPhase runPhase) [0x00025] in <785327a3fe2e4d2ebe5e223bef6e3faa>:0
  at Vintagestory.Server.ServerSystemModHandler.OnBeginGameReady (_wTXE2v1LflyYDnwkuDFOLi4HPJm savegame) [0x00000] in <785327a3fe2e4d2ebe5e223bef6e3faa>:0
  at Vintagestory.Server.ServerMain.EnterRunPhase (Vintagestory.API.Server.EnumServerRunPhase runPhase) [0x0009a] in <785327a3fe2e4d2ebe5e223bef6e3faa>:0
  at Vintagestory.Server.ServerMain.Launch () [0x002b4] in <785327a3fe2e4d2ebe5e223bef6e3faa>:0
  at ?????????????????????????????????????????.????????????????????????????????????????? () [0x000ce] in <46462d398d354fd8929b482784f4efa0>:0
  at _eVFDVqwXngafMmcD9boVPO86iWx._hbMghNVJIKTGI5zBx3SuxRG1XDI (System.Threading.ThreadStart ) [0x00007] in <785327a3fe2e4d2ebe5e223bef6e3faa>:0
-------------------------------
Crash written to file at "/home/server/data/Logs/server-crash.txt"

Unhandled Exception occurred
Version: ??????????????? ?????? artEA#8001 v1.14.0 (Stable)01/14/2021 11:23:09: Critical error occurred
System.NullReferenceException: Object reference not set to an instance of an object
  at DSharpPlus.DiscordClient.Dispose () [0x00056] in <73bf8d85ff3e42158583ab7e0be5fd9f>:0
  at DSharpPlus.DiscordClient.Finalize () [0x00000] in <73bf8d85ff3e42158583ab7e0be5fd9f>:0
-------------------------------
Crash written to file at "/home/server/data/Logs/client-crash.txt"

[ERROR] FATAL UNHANDLED EXCEPTION: System.NullReferenceException: Object reference not set to an instance of an object
  at DSharpPlus.DiscordClient.Dispose () [0x00056] in <73bf8d85ff3e42158583ab7e0be5fd9f>:0
  at DSharpPlus.DiscordClient.Finalize () [0x00000] in <73bf8d85ff3e42158583ab7e0be5fd9f>:0

 

 

Object reference not set to an instance of an object

  

On 1/10/2021 at 6:42 PM, Capsup said:

 

I'm assuming you don't see the message 



[Notification] vschatbot: connected to discord and ready!

before that error?
In that case, is your configuration actually correct?

Also, I think a race condition can occur here if your network is too slow in comparison to server startup, the VS server itself will attempt to send a 'ready' message to Discord before the bot has actually connected. Anyways, I added a simple check so it just discards the message at that point. Will be included in the next release.

The problem is that the server is crashing. Absolutely. Every time (Although everything worked fine recently.

Edited by momai Alex
Link to post
Share on other sites

Hey @Capsup we get the following CrashReport, after crashing the server caused by the Discord Mod. Can you please check, what happend here? Thank you :)

 

-------------------------------
Version: v1.14.5 (Stable)1/18/2021 6:49:16 AM: Critical error occurred
System.NullReferenceException: Object reference not set to an instance of an object.
   at DSharpPlus.DiscordClient.SendMessageAsync(DiscordChannel channel, String content, Boolean tts, DiscordEmbed embed)
   at vschatbot.src.DiscordWatcher.sendDiscordMessage(String message, DiscordEmbed embed) in C:\source\civcraft\vsmods\mods-dll\vschatbot\src\DiscordWatcher.cs:line 244
   at vschatbot.src.DiscordWatcher.Event_ServerShutdown() in C:\source\civcraft\vsmods\mods-dll\vschatbot\src\DiscordWatcher.cs:line 216
   at Vintagestory.Server.ServerEventAPI.OnServerStage(EnumServerRunPhase runPhase)
   at Vintagestory.Server.ServerSystemModHandler.OnBeginShutdown()
   at Vintagestory.Server.ServerMain.EnterRunPhase(EnumServerRunPhase runPhase)
   at Vintagestory.Server.ServerMain.Stop(String reason)
   at ‮‭‏‬‫‮‎‫‏‬‍‍‭‌‫‍‫‮‎‭‎‪‏‌‮‭‮‭‮‭‍‮._dkdtGIYBc54jrhL1MsbExekePPDA(Object , EventArgs )
   at VSPlatform.XPlatImplWin.ConsoleCtrlCheck(CtrlTypes ctrlType)
-------------------------------

 

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.