SinisterRectus / Discordia

Discord API library written in Lua for the Luvit runtime environment
MIT License
688 stars 144 forks source link

I can't get callback from bot #403

Closed 0Q1BE closed 7 months ago

0Q1BE commented 7 months ago

Hello. I was writing program that will add role to player when he joins the server, BUT when I was testing it from my twink account I didn't get any callback, but how if I even use print()!?

Code:

local onAddRole = '123456789'

client:on('messageCreate', function(message)
    local splitted = split(message.content)
    if splitted[1] == "!setOnAddRole" then
        onAddRole = splitted[2]
        print(onAddRole)
    end
end)

client:on('memberJoin', function(member)
    print(member.name)
    local success = false
    repeat 
        local success = member:addRole(onAddRole)
    until success == true
end)

client:run("TOKEN HERE")

Please, help me with this.

TohruMKDM commented 7 months ago

To track members and receive member related events such as memberJoin you need to have the Server Members privileged intent enabled on your application's dashboard. Also, since Discordia v2.11.0, you also need to explicitly define what privileged intents you want to use in your code as well using methods such as client:enableAllIntents() or client:enableIntents(...)

local discordia = require("discordia")
local client = discordia.Client()
client:enableIntents(discordia.enums.gatewayIntent.guildMembers)

P.S. You can get help quicker using the official discord

0Q1BE commented 7 months ago

Thank you very much!