Anyone know how to script a discord bot?

I scripted the script but.
Where do I find the discord.login
the channel id or the ban channel id
Need help thanks.


print(user.type);

local channelId = "0";

local banChannel = "0"; ```

Really need to get it connected to my channel.
1 Like

Can you show your full code? It’s hard to tell what you’re doing here without context.

1 Like

Why is discord bot coding allowed in ROBLOX? This makes no sense.

local discord = require(script.DiscordAPI);
local mutex = require(script.GlobalMutex);

local user = discord.Login("example");
print(user.type);

local channelId = "0";
local banChannel = "0";

game.Players.PlayerAdded:connect(function(player)
	local msgs = user:GetChannelMessages(banChannel,100);
	for i,v in next,msgs do
		local data = v.content;
		if tonumber(data) == player.UserId then
			player:Kick("You have been banned.");
		end
	end
	
	player.Chatted:connect(function(msg)
		if player:GetRankInGroup(0) < 0then return end;
		msg = msg:lower()
		local plr = msg:match("^:dban (.+)");
		if not plr then return end;
		
		for i,v in next,game.Players:GetPlayers() do
			if v.Name:lower():sub(1,#plr) == plr then
				plr = v;
				break;
			end
		end
		
		if plr:GetRankInGroup(0) >= 0then return end;
		plr:Kick("You have been banned");
		user:SendMessage(banChannel,plr.UserId);
	end)
end)

function _G.DiscordMsg(msg)
	user:SendMessage(channelId,msg);
end

mutex.Lock();

game:BindToClose(function()
	mutex.Unlock();
end)

user:ListenChat({channel=channelId});

while wait(1) do
	if mutex.CheckLock() then
		user:BindCallback("message",function(data)
			local msg = data.content;
			local cmd = msg:match("^:(%a+)");
			
			if cmd == "rolldie" then
				user:SendMessage(channelId,"You rolled a: "..math.random(1,6));
			end
		end)
		break;
	end
end
2 Likes

Perhaps it’s the HttpService you’re looking for and a webhook to execute or log things from.

Guessing


My guess is that you’re trying to use a webhook from Discord. Unfortunately, Osyris has discontinued the proxy because they announced that Discord is not blocking the requests anymore.

Using the URL of the webhook(and some proper API usage of the webhook) should allow you to log messages and events around your game.

Oh, wait can I send you the full script?
with the modules and that?

Sure… but I’m unable to work with the scripts at these hours. I’ll check back later and see what results I can extract when I can.

Oh, by the way, don’t webhooks have designated channels?

Does this poll Disccord’s servers? If so that is against their ToS and you shouldn’t do that.

1 Like

That’s unrelated to actually getting the channel details. You’ll have to look at the actual Discord API documentation for that. That being said; I don’t know how to do that myself.

Discord isn’t a logging service. Lack of respect for rate limits (even though one is hard enforced by Roblox now) is not the only way that a webhook can be removed. In some cases, disciplinary action may be taken against your server or even your account itself. I know it’s an example but it’s a poor one; don’t log messages with Discord.

3 Likes

discord is not supposed to be used as a logging service, as @colbert2677 said, for logging use GA, or Sentry, they’re good logging/analytic services.

edit: it will most likely get your account terminated and so on, chat messages in roblox should never be logged, otherwise if you really want to, create an external database, and store all messages there.<

edit2: or you create a discord bot, and then host it for example on AWS, Heroku, and so on.
and then listen for posts on a port, which the bot will then post in a logging channel, that will probably not get your account banned, because you’re still respecting the discord webhook rate limits, because you’re not using a webhook to log everything.

edit3: discord bots doesnt have rate limits, so you’re good with using this possible solution.