Search code examples
luadiscordbotsluvit

Why isn't "bulkDelete()" working in my bot command?


I'm trying to code a Discord bot in lua at the moment and I've having some difficulties. I'm trying to create a bulk delete command for my bot, but it seems to not work and only returns "400 - Bad Request" upon typing the command. Am I doing something wrong? I've tried doing message.channel:bulkDelete(3) and it still doesn't work. (I am pretty new to coding Discord bots in lua.)

Code:

local discordia = require('discordia')
local client = discordia.Client()

local prefix = "+"
local adminid = 645671868728082432

client:on("ready", function() -- bot is ready
    print("Logged in")
end)

client:on("messageCreate", function(message)
    local content = message.content
    local member = message.member
    local author = message.author
    local memberid = member.id
    local args = content:split(" ")

    if args[1] == prefix.. "delete" then
        if not member:hasRole(adminid) then
            message:reply("<@" ..author.id.. ">**, you do not have permission to use this command.**")
            return
        end
        message.guild:getChannel(message.channel.id):bulkDelete(3)
    end
end)

Solution

  • Because this method requires a table of MessageID-resolvable objects like Message object itself or its ID as string.

    Read documentation here: https://github.com/SinisterRectus/Discordia/wiki/GuildTextChannel#bulkdeletemessages