Adding discord in server

Started by Nihongo^, Jun 18, 2022, 05:51 AM

Previous topic - Next topic

Nihongo^

Hi friends hope you guys are fine

So i am scripting a server and now its time to put discord on it, I am completely new in the world of discord features. I only know about the IRC and it was simple now we have to move to discord :D

i did some research and found [MODULE] Discord module for SqMod

I put the plugins and install OpenSSL, the plugin loaded successfully but it gave error at "Constructor"

I only put discord.nut and plugins


habi

Add
print(session);just before line 32.
This is to know if variable session is null.

Nihongo^

Quote from: habi on Jun 18, 2022, 12:30 PMAdd
print(session);just before line 32.
This is to know if variable session is null.


Thanks for you kind reply. It said 0x0000


habi

#3
QuoteThanks for you kind reply. It said 0x0000
it's ok.
The variable therefore is not null. It is an instance of CSession class.
This instance is supposed to have member InternalCacheEnabled,  as the source of the discord module shows when i checked it.
Could you try the following code just before line 32 ( remove earlier print statement) and post the output. (To copy an area of console in windows,  first select it by mouse. When it is white colour,  press enter)
foreach(key,  val in session)
print(key+ " " + val +"\n");

habi

#4
Ah,  i figured this out.  There are two discord plugins made by Luckshya.
Discord module for SqMod

Discord module for Squirrel

Both have their own wiki and example codes.

You probably want the second one,  since the code in the first post is for squirrel.

Nihongo^

#5
I did some research and found this
https://forum.vc-mp.org/?topic=8869.msg52280#msg52280

I am successfully recevnig the message on my console what ever i am writing on discord. But i am confused how do i send messages in server when i type on discord ? and same discord to server

Please guide me on it
thank you

habi

#6
Hi
If you are using dcdbot.nut and main.nut in topic?8869,  then
function onPlayerChat( player, message )
{
myDiscord.sendMessage(player.Name + ": "+ message);
}

Can you see messages send in discord in the server console?
If yes,  then this is the homework for you: Receive messages from discord and show it in server. Hint: Use Message function of squirrel and work on dcdbot.nut. Find onMessage function.
function onMessage(message) {
  if(!targetchannelID || targetchannelID==message.ChannelID)
  {
   print("[Discord]"+message.Member.User.Username+": "+message.Content);
  }
 }



[Discord]

Nihongo^

Its worked Thank you so much habi

Nihongo^

I forgot to ask about sending messages in the server from discord.
like !say<text>. with discord rank

habi

#9
I guess you meant Discord Roles which are assigned to server members.

There does not exit any material on this.

Suppose there are 3 roles created in your discord server: owner, admin, moderator
There can be more roles. But you only want these three people to use command "!say".

Modify your dcdbot.nut
dcdbot.nut (part)
function onMessage(message) {
if(!targetchannelID || targetchannelID==message.ChannelID)
{
local array=GetCmdAndText(message.Content);
if(array)
{
local cmd=array[0]; local text=array[1];
if(cmd=="say" && text){
local member = message.Member;
local serverID = message.ServerID;

if(member != null && serverID != null) {
foreach(roleID in member.Roles) {
local role=session.GetRoleName(serverID, roleID);
if(role=="moderator"||role=="admin"||role=="owner"){
print("[Discord]"+member.User.Username+": "+text);
break;
}
}
}

}
}
}

}
Don't copy paste. Read it and understand. Make necessary changes like role names.

Here is the GetCmdAndText function used
function GetCmdAndText(message)
{

local cmd=null;local text=null;
if(message.len()>1 && message[0]=='!')
{
local idx=message.find(" ");
if(idx)
{
cmd=message.slice(1,idx);
if(message.len()>idx+1)
{
text=message.slice(idx+1);
}
}else cmd=message.slice(1);
return [cmd, text];
}
}

Results:


Nihongo^

#10
Thank you so much its works for me I modified the code and now I can see the role too

I have 2 more questions how do I send this message to the server? I mean its printing on the console only

and what role for the normal player?

I tried to make this but didn't work

if(role=="moderator"||role=="admin"||role=="Owner")
 {
  print("[Discord]" +role+ "" +member.User.Username+": "+text);
  }
  else
  {
  print("Memeber" +member.User.Username+": "+text);
  break;
 }

habi

#11
By normal player, you have meant those discord users in the server on whom no roles are assigned.

In that case using else part of the if statement
if(role=="moderator"||role=="admin"||role=="Owner"){is not correct,  because normal player has no roles.

In that case member.Roles will be an empty array.

Therefore this loop will not be executed:
foreach(roleID in member.Roles) {
      local role=session.GetRoleName(serverID, roleID);
      if(role=="moderator"||role=="admin"||role=="owner"){
       print("[Discord]"+member.User.Username+": "+text);
       break;
      }
     }
So just after the loop (after the closing brace of loop) add this:
if(member.Roles.len()==0)
{
// here code for user with no roles
}

This code is not tested yet.

....

Quotehow do I send this message to the server? I mean its printing on the console only
QuoteHint: Use Message function of squirrel
Using print statement will print to console and using Message statement will output in game.

Nihongo^

Hi i tried Message function of squirrel but its gives error here .


habi

Put comma ( , ) after text
ClientMessageToAll(...+": "+text, 255, 0, 255);

Nihongo^

Sorry still giving the same error after putting the comma