SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Plugin Development

Reply
 
Thread Tools Display Modes
Old 31/03/2017, 09:16 PM   #1
maddinat0r
Gangsta
 
maddinat0r's Avatar
 
Join Date: Jun 2010
Location: Germany
Posts: 881
Reputation: 459
Default Discord Connector

Discord Connector v0.2


This plugin allows you to control a Discord bot from within your gamemode.

Installation
You'll need to create a bot first in order to pass your bot token to the plugin.
  1. Go to https://discordapp.com/developers/applications/me
  2. click "new application"
  3. enter a name for your bot
  4. click "create application"
  5. press "create bot user"
  6. you now have a bot token!
To add that bot to your server, copy the client id from your newly created application, insert it in the link below and open that link:
Code:
https://discordapp.com/api/oauth2/authorize?client_id=YOURCLIENTIDGOESHERE&scope=bot&permissions=0
Now you only have to add this line into your server.cfg file and you're ready to go!
Code:
discord_bot_token YOUR_BOT_TOKEN_HERE
Notes
  • never share your bot token with anyone
  • make sure your server clock is synced regularly, or else the rate-limiter won't work correctly and your bot might get banned
  • this plugin won't run on CentOS 6, you'll need CentOS 7 at least

Example code
Code:
new DCC_Channel:g_WelcomeChannelId;

public OnPlayerSpawn(playerid)
{
	new name[MAX_PLAYER_NAME + 1];
	GetPlayerName(playerid, name, sizeof name);
	
	if (_:g_WelcomeChannelId == 0)
		g_WelcomeChannelId = DCC_FindChannelById("388423556721672192"); // Discord channel ID
	
	new str[128];
	format(str, sizeof str, "Player %s joined the server.", name);
	DCC_SendChannelMessage(g_WelcomeChannelId, msg);
	return 1;
}

public DCC_OnChannelMessage(DCC_Channel:channel, DCC_User:author, const message[])
{
	new channel_name[100 + 1];
	if(!DCC_GetChannelName(channel, channel_name))
		return 0; // invalid channel

	new user_name[32 + 1];
	if (!DCC_GetUserName(author, user_name))
		return 0; // invalid user

	new str[145];
	format(str, sizeof str, "[Discord/%s] %s: %s", channel_name, user_name, message);
	SendClientMessageToAll(-1, str);
	return 1;
}
Disclaimer
This plugin is still in beta. If you notice the plugin spawns a lot of errors/warnings in its log, stop using it, or your bot might get banned.
The plugin will also generate a lot of debug log messages for now. This should help me on improving it, in case of bugs/crashes.

Where da links at
Source on GitHub
Download on GitHub

Please provide feedback and log files if you can.

Last edited by maddinat0r; 24/09/2017 at 10:19 AM. Reason: v0.2
maddinat0r is offline   Reply With Quote
Old 31/03/2017, 09:17 PM   #2
Kar
High-roller
 
Kar's Avatar
 
Join Date: May 2010
Location: Black Asylum
Posts: 3,125
Reputation: 450
Default Re: Discord Connector

Finally guys! We got it!
Kar is offline   Reply With Quote
Old 31/03/2017, 09:28 PM   #3
Tamer
High-roller
 
Tamer's Avatar
 
Join Date: Nov 2011
Location: Turkey
Posts: 1,200
Reputation: 169
Default Re: Discord Connector

Thanks for the effort, awaiting further updates.
__________________
The three stages of truth:

- Ridicule.
- Violent opposition.
- Acceptance.


Quote:
The greatest hypnotist on the planet Earth is an oblong box in the corner of the room. It is constantly telling us what to believe is real. If you can persuade people that what they see with their eyes is what there is to see you've got them. you know because they'll laugh in your face of an explanation that portrays the biggest picture of what's happening... and they have.
Tamer is offline   Reply With Quote
Old 31/03/2017, 09:33 PM   #4
Dayvison_
High-roller
 
Dayvison_'s Avatar
 
Join Date: Nov 2013
Posts: 1,258
Reputation: 171
Default Re: Discord Connector

Finally, thanks a lot
Dayvison_ is offline   Reply With Quote
Old 31/03/2017, 10:17 PM   #5
Evocator
Huge Clucker
 
Join Date: Nov 2013
Posts: 483
Reputation: 150
Default Re: Discord Connector

Yep, interesting. Thanks maddinat0r!
Evocator is offline   Reply With Quote
Old 01/04/2017, 12:10 AM   #6
Admigo
High-roller
 
Admigo's Avatar
 
Join Date: Oct 2010
Location: The Netherlands
Posts: 2,027
Reputation: 274
Default Re: Discord Connector

Thanks for this great release maddinat0r!
__________________

Admigo is offline   Reply With Quote
Old 01/04/2017, 12:16 AM   #7
JustMe.77
Huge Clucker
 
JustMe.77's Avatar
 
Join Date: Jun 2013
Location: Germany
Posts: 273
Reputation: 63
Default Re: Discord Connector

This is damn cool, can't wait for more functions !
JustMe.77 is offline   Reply With Quote
Old 01/04/2017, 12:23 AM   #8
TopShooter2
Big Clucker
 
TopShooter2's Avatar
 
Join Date: Feb 2017
Posts: 127
Reputation: 55
Default Re: Discord Connector

Good job, thank you for releasing it.
TopShooter2 is offline   Reply With Quote
Old 01/04/2017, 01:44 AM   #9
ISmokezU
Gangsta
 
Join Date: Aug 2016
Posts: 546
Reputation: 58
Default Re: Discord Connector

Been waiting for this quite a while now, Ditching IRC for sure!
ISmokezU is offline   Reply With Quote
Old 01/04/2017, 01:51 AM   #10
Iszcegg
Gangsta
 
Iszcegg's Avatar
 
Join Date: Oct 2013
Location: Venezuela
Posts: 832
Reputation: 81
Default Re: Discord Connector

Excelent job, 5 stars and +rep.
Iszcegg is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[Plugin] Teamspeak Connector maddinat0r Plugin Development 314 09/06/2017 08:46 AM
Route Connector James_Braga Русский/Russian 9 15/05/2015 09:24 AM
[Map] Connector Gas Tellken Maps 4 01/06/2012 04:04 AM
PSU connector help! patchkinson Everything and Nothing 3 20/03/2010 10:24 PM


All times are GMT. The time now is 06:29 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.