Lua Discord bot using discordia library fails to add reactions

I’m working on a Discord bot written in Lua and I’m having trouble getting it to add reactions to messages. When my bot tries to react to its own message, I keep getting an error that says:

/Desktop/Bot/main.lua:96: attempt to call method 'reactionAdd' (a nil value)

Here’s the code I’m using to make the bot add a reaction:

if msg.content == "say hello" then
    if msg.author.bot then
        msg.reactions:addReaction(":thumbsup:")
    end
end

I thought this would work but apparently the reactionAdd method doesn’t exist or I’m calling it wrong. Has anyone dealt with this before? What’s the correct way to make a bot react to messages in discordia?

Others covered the direct fix, but this is exactly why I ditched manual Discord bot coding. Too many library quirks and version headaches.

I use Latenode for all my Discord automation now. Instead of fighting discordia method names, you drag and drop Discord nodes and connect them visually. Need reactions? There’s a node for that. Want to respond to specific messages? Another node handles the triggers.

Best part - no worrying about library updates breaking your code. When Discord changes their API, Latenode updates the nodes automatically. I’ve built complex Discord workflows in minutes that would’ve taken hours to debug in raw Lua.

You can also connect your bot to other services without writing integration code. Database logging, webhooks, external APIs - all drag and drop.

Check it out at https://latenode.com

The issue arises from the method name. In the discordia library, you should use addReaction, but it must be called directly on the message object. So the corrected code would look like this:

if msg.content == "say hello" then
    if msg.author.bot then
        msg:addReaction(":thumbsup:")
    end
end

Currently, your code will only react if a bot sends “say hello”. If you want it to react to any user, you can remove the check for msg.author.bot or use not msg.author.bot. I remember this tripping me up when I started with discordia; their documentation isn’t as clear as it could be.

You’re accessing reactions incorrectly. msg.reactions is only for reading existing reactions, not adding new ones. You should call the method directly on the message object:

if msg.content == "say hello" then
    if msg.author.bot then
        msg:addReaction("👍")
    end
end

You can also use Unicode emoji directly instead of the colon syntax. I encountered the same confusion when starting out; seeing the reactions property misled me into thinking that’s where to call the add method. The message object manages all reaction functionalities directly.

had the exact same issue a few months back. use the actual emoji unicode instead of :+1: - that fixed it for me. also check your discordia version since older ones use different method names for reactions.