This wrapper allows you easily create an instance of a discord bot within your RAGE:MP server.
Features:
- Send messages to discord from your RAGE:MP Server.
- Send messages to your RAGE:MP Server from your Discord server.
- Register specific channel for the bot to listen. (Can be changed during runtime).
- Remove specific channel for the bot to STOP listening. (Can be changed during runtime).
- Update bot status on setup and/or during runtime
- Create a new application on Discord Developers
- Create a bot.
- Invite bot to discord server.
- Use the token from your bot to initialize the bot as shown in the example below.
- Register/Remove channels from where your bot sends to all players.
using GTANetworkAPI;
using System;
using System.Collections.Generic;
using System.Text;
public class Yes : Script
{
public Yes()
{
NAPI.Util.ConsoleOutput("Loaded: yes");
}
[ServerEvent(Event.ResourceStart)]
public void OnResourceStart()
{
Integration.DiscordIntegration.SetUpBotInstance("TOKEN_HERE", "RAGE:MP", Discord.ActivityType.Playing, Discord.UserStatus.DoNotDisturb);
}
[ServerEvent(Event.ChatMessage)]
public async void OnChatMessage(Player player, string strMessage)
{
string strFormatted = $"[RAGE:MP] {player.Name}: {strMessage}";
await Integration.DiscordIntegration.SendMessage(3897429387492374, strFormatted, true).ConfigureAwait(true);
}
[Command("registerchannel")]
public void RegisterDiscord(Player player, ulong discordChannelID)
{
bool bSuccess = Integration.DiscordIntegration.RegisterChannelForListenting(discordChannelID);
player.SendChatMessage(bSuccess ? "Success" : "No Success");
}
[Command("removechannel")]
public void RemoveDiscordChannel(Player player, ulong discordChannelID)
{
bool bSuccess = Integration.DiscordIntegration.RemoveChannelFromListening(discordChannelID);
player.SendChatMessage(bSuccess ? "Success" : "No Success");
}
[Command("botstatus")]
public async void UpdateBotStatusCommand(Player player, string gameName, Discord.ActivityType eActivityType, Discord.UserStatus eUserStatus)
{
await Integration.DiscordIntegration.UpdateStatus(gameName, eActivityType, eUserStatus).ConfigureAwait(true);
}
}