Creating A Discord Bot With Lua

Installing Luvit - Luvit.io there you go open command prompt if you on windows and then direct to the folder of your bot and type PowerShell -NoProfile -ExecutionPolicy unrestricted -Command "[Net.ServicePointManager]::SecurityProtocol = 'Tls12'; iex ((new-object net.webclient).DownloadString('https://github.com/luvit/lit/raw/master/get-lit.ps1'))"

Nah, it is okay now - it has been 2 months lol

1 Like

Hi there! Great tutorial! I’ve always wanted to create a discord bot! Do you know if there is a way to do this on a Mac? I tried using this tutorial but the commands started being too different to work. Is there by chance a way to do this on Mac?

1 Like

You could just use webhooks, this isn’t needed.

1 Like

This is just a simple demonstration into being able to code a Discord bot in Lua. Webhooks are different and don’t have all the same functionalities that a bot does.

2 Likes

is there a way to script discord bot with lua without luvit?

1 Like

Yes, however you’d need to utilize Discord.Js or Discord.py for that.

3 Likes

Discord.JS is the best library to use for new bot developers.

2 Likes

Thanks a lot I can now be lazy and only have to learn lua :slight_smile:

2 Likes

Yes, the library is much more rich and powerful in terms of the library, functions, a wide range of situations where it can be applicable, and more. Python is definitely a language worth taking into consideration and for some, it is a plan that suitably better works out for them. When considering your first language many users forget to take into perspective that you’re not likely to receive any too much support if you go and try to code a discord application in rust or ruby. The syntax is simple and easy to understand with Javascript much more than Python.

1 Like

If you won’t be using the bot on many servers then a JSON file you can read or write to would work fine

1 Like

MySQL would be more efficient even for single server use because of how corruptible JSON files are if something goes wrong.

2 Likes

Hello everyone,
I’m truemedian, a contributor to Discordia and Luvit.

I’m aware that this is quite old but I would like to clarify a few things in this thread.

Require Bugs

While this is indeed a bug with luvit’s require, the way you should fix it is by using require with relative paths, such as require('./file.lua').
It’s a known issue and pain point of luvit that we cannot fix because we must maintain backwards compatibility. It exists because luvit actually implements its own require in order to properly use the deps/ folder created when installing dependencies via lit. However when it cannot find the library or file you provide it, it falls back upon lua’s require, which doesn’t know about the deps/ folder. This action is a one way door, once you leave luvit’s special environment, you cannot re-enter it.

(Scheduled) Coroutines

This is technically incorrect. Luvit simply schedules coroutines with an event loop (exactly how roblox does coroutines, only on single thread) in order to continue doing things that take forever: such as making network requests (we can be doing better things with our time than waiting).

Catching Console Errors

The recommended way to do this is to actually do

luvit bot
pause

The pause at the end will cause the terminal to remain open until a key is pressed when the bot errors unexpectedly. This is very helpful in catching errors.

This is another way to get a similar output.

Installing Luvit

If you’ve seen mentions of SinisterRectus/get-lit, it was to solve a temporary problem with the luvit installation process and has since been archived and eventually was deleted.

We understand that installing luvit is quite painful or impossible for some users. This could be for a multitude of reasons (often your antivirus). Another issue that has come up for some users is that the luvit project stopped prebuilding ARM Linux luvi binaries (which are required for the luvit installation process).

Because of this I have begun publishing Luvit, Luvi, and Lit binaries for Windows (64-bit), MacOS (64-bit), and Linux (64-bit and ARM).

Other Notes

I am glad to see such a nice beginner tutorial on how to start with a Discordia project. I hope we can continue getting people like this to use, and possibly eventually contribute to the project.

Discordia 3.0 is currently under development, so eventually this guide will be wrong if you’re using the latest version of Discordia. This is just a warning for those reading this in the future. I will try to remember to update this message when the time comes.

3 Likes

What do I do here?

‘cmake’ is not recognized as an internal or external command,
operable program or batch file.
image

1 Like

Unless you’re on a system that luvit doesn’t have prebuilt binaries for, you shouldn’t need to build luvi from source. Building from source requires a system setup for building (git, cmake, perl, and a c compiler in this case).

If you cannot get the installation scripts to work on your system. Please use the prebuilt binaries available here.

1 Like

thank you, I got it working, just got to familiarise myself with the docs

1 Like

sorry to be intrusive but can I get your Discord @?

1 Like

Its Nameless#1814, but you’re likely to find me in either of the discord servers mentioned in the README.

1 Like

Ah cripes, I forgot about this thread.

I’ve come a ways since then both with Discordia/Luvit and programming in general so I apologize for that whole thing. If I were to write that post now it would be a lot less… terrible.

1 Like

Are you still looking for help on this topic, if so I can help!

1 Like