Thread: Basic Discord Chat Bot [Vencillio Base]

Results 1 to 7 of 7
  1. #1 Basic Discord Chat Bot [Vencillio Base] 
    Donator


    Join Date
    Nov 2012
    Age
    27
    Posts
    165
    Thanks given
    91
    Thanks received
    80
    Rep Power
    160
    Spoiler for Discord Part:
    Step 1. Create a discord bot and invite it to your server. Check out this guide if you don't know how to do that. Make sure to take note of your bot token (should look something like this: NzEyODgxMDE4HTgxNDQ5NzQ4.XsYAFQ.wBlWybN5UHDHL1XG35 imelotpCw! )

    Step 2. Create separate channels for whatever you want in discord. I'll go over logging regular chat to discord, logging in and out of the server, clan chat to discord, joining and leaving a clan, as well as sending messages back from discord to the server or to a clan chat.

    Step 3. Enable developer mode on discord.

    Step 4. Now you can right click all the channels you created and press "Copy ID" to get the id of the channel. You will need to take note of these.


    Spoiler for Coding Part:

    Step 1. Download Javacord and add it to your source build path. Download the one named javacord-3.0.6-shaded.jar

    Step 2. Open up com/vencillio/GameDataLoader.java
    Spoiler for GameDataLoader.java:

    Imports:
    Code:
    import org.javacord.api.DiscordApi;
    Under:
    Code:
    	private static int stage = 0;
    Add:
    Code:
    	public static DiscordApi discord;


    Step 3. Starting up the bot and sending messages from the discord to public chat and clan chat.
    Open up com/vencillio/Server.java
    Spoiler for Server.java:

    Imports:
    Code:
    import org.javacord.api.DiscordApiBuilder;
    import org.javacord.api.entity.channel.TextChannel;
    import com.vencillio.rs2.content.clanchat.Clan;
    Under this bit of code:
    Code:
    		if (!VencillioConstants.DEV_MODE) {
    			try {
    				MembershipRewards.prepare();
    				HiscoreUpdater.prepare();
    				VoteUpdater.prepare();
    				
    				
    			} catch (Exception ex) {
    				ex.printStackTrace();
    			}
    Add this bit of code and get ready to modify some stuff:
    Code:
    			//discord
    			GameDataLoader.discord = new DiscordApiBuilder().setToken("THE BOT TOKEN YOU SAVED IN THE BEGINNING").login().join();
    			TextChannel mainChannel = (TextChannel) GameDataLoader.discord.getChannelById("ID OF WHATEVER CHANNEL(THIS IS MY MAIN CHAT)").get();
    			TextChannel helpChannel = (TextChannel) GameDataLoader.discord.getChannelById("ID OF WHATEVER CHANNEL(THIS IS A HELP CLAN CHAT CHANNEL)").get();
    			GameDataLoader.discord.addMessageCreateListener(event -> {
    	            if (event.isServerMessage() && event.getChannel().equals(mainChannel)) {
    	                //yell
    	            	
    	            	if(!event.getMessageAuthor().isBotUser()) {
    	            		String text = "[Discord]"+event.getMessageAuthor().getDisplayName()+": "+event.getMessageContent().toString();
    	            		String[] strings = text.split("(?<=\\G.{75,}\\s)");
    	            		if(strings.length > 4) {
    	            			event.getChannel().sendMessage("Your message was too long and therefore not sent, "+event.getMessageAuthor().asUser().get().getMentionTag());
    	            		} else {
    	            			
    	            			Boolean tooLong = false;
    	            			for (String s : strings) {
    	            				if (s.length() > 100) {
    	            					tooLong = true;
    	            				}
    	            			}
    	            			
    	            			if (tooLong) {
                					event.getChannel().sendMessage("Your message was too long and therefore not sent, "+event.getMessageAuthor().asUser().get().getMentionTag());
    	            			} else {
    	            				for (String s : strings) {
    			            			World.sendGlobalMessage("@blu@"+s);
    			            		}
    	            			}
    	            			
    	            			
    	            		}
    	            		
    	            		
    		            	
    	            	}
    	            }
    	            
    	            
    	            if (event.isServerMessage() && event.getChannel().equals(helpChannel)) {
    	            	if(!event.getMessageAuthor().isBotUser()) {
    	            		Clan helpcc = clanManager.getClan("OWNER OF CLAN");
    	            		String text = "</col>[@blu@" + helpcc.getTitle() + "</col>] "+"[Discord]"+event.getMessageAuthor().getDisplayName()+": @dre@"+event.getMessageContent().toString();
    	            		String[] strings = text.split("(?<=\\G.{75,}\\s)");
    	            		if(strings.length > 4) {
    	            			event.getChannel().sendMessage("Your message was too long and therefore not sent, "+event.getMessageAuthor().asUser().get().getMentionTag());
    	            		}
    	            		else {
    	            			
    	            			Boolean tooLong = false;
    	            			for (String s : strings) {
    	            				if (s.length() > 100) {
    	            					tooLong = true;
    	            				}
    	            			}
    	            			
    	            			if (tooLong) {
                					event.getChannel().sendMessage("Your message was too long and therefore not sent, "+event.getMessageAuthor().asUser().get().getMentionTag());
    	            			} else {
    	            				for (String s : strings) {
    		            				
    		            				
    		            				if (s.equals(strings[0])) {
    		            					helpcc.sendMessage(s);
    		            				} else {
    		            					helpcc.sendMessage("@dre@" + s);
    		            				}
    			            			
    			            			
    			            		}
    	            			}
    	            			
    	            			
    	            		}
    	            		
    	            		
    		            	
    	            	}
    	            }
    	        });
    			//end discord
    You will need to change 4 strings:
    1. "THE BOT TOKEN YOU SAVED IN THE BEGINNING"
    2. "ID OF WHATEVER CHANNEL(THIS IS MY MAIN CHAT)"
    3. "ID OF WHATEVER CHANNEL(THIS IS A HELP CLAN CHAT CHANNEL)"
    4. "OWNER OF CLAN"


    Step 4. Public chat messages going to discord.
    Open com/vencillio/rs2/entity/player/net/in/impl/PublicChatPacket.java
    Spoiler for PublicChatPacket.java:

    Imports:
    Code:
    import org.javacord.api.entity.channel.TextChannel;
    import com.vencillio.GameDataLoader;
    import com.vencillio.core.util.Utility;
    Under this bit of code:
    Code:
    		} else {
    			player.setChatUpdateRequired(true);
    			ReportHandler.addText(player.getUsername(), text, chatLength);
    Add this bit of code and change "MAIN DISCORD CHANNEL ID" to whatever it was. You should've already used it in Server.java:
    Code:
    			//discord
    			TextChannel channel = (TextChannel) GameDataLoader.discord.getChannelById("MAIN DISCORD CHANNEL ID").get();
    			String ts = "";
    	        ts = ts + player.getUsername()+": ";
    			channel.sendMessage("**"+ts+"**"+"`"+Utility.textUnpack(text, chatLength, false)+"`");


    Step 5. Sending a message to discord whenever someone logs in or out. Open up com/vencillio/rs2/entity/player/Player.java:
    Spoiler for Player.java:

    Imports:
    Code:
    import org.javacord.api.entity.channel.TextChannel;
    import com.vencillio.GameDataLoader;
    Under this bit of code and right above World.unregister(this);
    Code:
    			if (DwarfMultiCannon.hasCannon(this)) {
    				DwarfMultiCannon.getCannon(this).onLogout();
    			}
    
    			PlayerSave.save(this);
    
    			if (!VencillioConstants.DEV_MODE) {
    				//HiscoreUpdater.update(this);
    			}
    		}
    Add this bit of code and change "MAIN DISCORD CHANNEL ID" to whatever it was. You should've already used it in Server.java:
    Code:
    		TextChannel channel = (TextChannel) GameDataLoader.discord.getChannelById("MAIN DISCORD CHANNEL ID").get();
    		String ts = "";        
            ts = ts + "**"+this.getUsername()+" has left the server.**";
            channel.sendMessage(ts);
    Under this bit of code:
    Code:
    		if (PlayerConstants.isStaff(this)) {
    			send(new SendString("Staff tab", 29413));
    		} else {
    			send(new SendString("", 29413));
    		}
    		send(new SendConfig(1990, getTransparentPanel()));
    		send(new SendConfig(1991, getTransparentChatbox()));
    		send(new SendConfig(1992, getSideStones()));
    Add this bit of code and again change "MAIN DISCORD CHANNEL ID" to whatever it was. You should've already used it in Server.java:
    Code:
    		TextChannel channel = (TextChannel) GameDataLoader.discord.getChannelById("MAIN DISCORD CHANNEL ID").get();
    		String ts = "";        
            ts = ts + "**"+this.getUsername()+" has joined the server.**";
            channel.sendMessage(ts);


    Step 6. Clan chat, leaving a clan, joining a clan. Open up com/vencillio/rs2/content/clanchat/Clan.java
    Spoiler for Clan.java:

    Imports:
    Code:
    import org.javacord.api.entity.channel.TextChannel;
    import com.vencillio.GameDataLoader;
    Under this bit of code:
    Code:
    		paramPlayer.getClient().queueOutgoingPacket(new SendString("Leave chat", 18135));
    		paramPlayer.getClient().queueOutgoingPacket(new SendString("</col>Talking in: <col=FFFF64><shad=0>" + getTitle(), 18139));
    		paramPlayer.getClient().queueOutgoingPacket(new SendString("</col>Owner: <col=FFFF64><shad=0>" + Utility.formatPlayerName(getFounder()), 18140));
    		paramPlayer.getClient().queueOutgoingPacket(new SendMessage("Attempting to join clan channel..."));
    		paramPlayer.getClient().queueOutgoingPacket(new SendMessage("Now talking in clan chat <col=FFFF64><shad=0>" + getTitle() + "</shad></col>."));
    		paramPlayer.getClient().queueOutgoingPacket(new SendMessage("To talk, start each line of chat with the / symbol."));
    		updateMembers();
    Add this bit of code and change "OWNER OF CLAN" to the owner of the clan chat you want discord messages sent to and from, and change "DISCORD CLAN CHANNEL ID" to the id of the clan channel on discord.
    Code:
    		if (this.founder.equalsIgnoreCase("OWNER OF CLAN")) {
    			//discord
    			Player player = paramPlayer;
    			TextChannel channel = (TextChannel) GameDataLoader.discord.getChannelById("DISCORD CLAN CHANNEL ID").get();
    			String ts = "";
    	        ts = ts + player.getUsername()+" has joined the clan chat.";
    			channel.sendMessage("**"+ts+"**");
    		}
    Under this bit of code:
    Code:
    	public void removeMember(Player paramPlayer) {
    		for (int i = 0; i < this.activeMembers.size(); i++) {
    			if (this.activeMembers.get(i).equalsIgnoreCase(paramPlayer.getUsername())) {
    Add this bit of code and change "OWNER OF CLAN" to the owner of the clan chat you want discord messages sent to and from, and change "DISCORD CLAN CHANNEL ID" to the id of the clan channel on discord.
    Code:
    				if (this.founder.equalsIgnoreCase("OWNER OF CLAN")) {
    					//discord
    					Player player = paramPlayer;
    					TextChannel channel = (TextChannel) GameDataLoader.discord.getChannelById("DISCORD CLAN CHANNEL ID").get();
    					String ts = "";			        
    			        ts = ts + player.getUsername()+" has left the clan chat.";
    					channel.sendMessage("**"+ts+"**");
    				}
    Under this bit of code:
    Code:
    	public void removeMember(String paramString) {
    		for (int i = 0; i < this.activeMembers.size(); i++) {
    			if (this.activeMembers.get(i).equalsIgnoreCase(paramString)) {
    				Player localPlayer = World.getPlayerByName(paramString);
    				if (localPlayer != null) {
    Add this bit of code and change "OWNER OF CLAN" to the owner of the clan chat you want discord messages sent to and from, and change "DISCORD CLAN CHANNEL ID" to the id of the clan channel on discord.
    Code:
    					if (this.founder.equalsIgnoreCase("OWNER OF CLAN")) {
    						//discord
    						Player player = localPlayer;
    						TextChannel channel = (TextChannel) GameDataLoader.discord.getChannelById("DISCORD CLAN CHANNEL ID").get();
    						String ts = "";        
    				        ts = ts + player.getUsername()+" has left the help chat.";
    						channel.sendMessage("**"+ts+"**");
    					}
    Under this bit of code:
    Code:
    		if (paramPlayer.isMuted()) {
    			if (paramPlayer.getMuteLength() == -1) {
    				paramPlayer.send(new SendMessage("You are permanently muted on this account."));
    				return;
    			} else {
    				long muteHours = TimeUnit.MILLISECONDS.toMinutes(paramPlayer.getMuteLength() - System.currentTimeMillis());
    				String timeUnit = "hour" + (muteHours > 1 ? "s" : "");
    				if (muteHours < 60) {
    					if (muteHours <= 0) {
    						paramPlayer.send(new SendMessage("Your mute has been lifted!"));
    						paramPlayer.setMuted(false);
    					}
    					timeUnit = "minute" + (muteHours > 1 ? "s" : "");
    				} else {
    					muteHours = TimeUnit.MINUTES.toHours(muteHours);
    				}
    				if (paramPlayer.isMuted()) {
    					paramPlayer.send(new SendMessage("You are muted, you will be unmuted in " + muteHours + " " + timeUnit + "."));
    					return;
    				}
    			}
    		}
    Add this bit of code and change "OWNER OF CLAN" to the owner of the clan chat you want discord messages sent to and from, and change "DISCORD CLAN CHANNEL ID" to the id of the clan channel on discord.
    Code:
    		if (this.founder.equalsIgnoreCase("OWNER OF CLAN")) {
    			//discord
    			Player player = paramPlayer;
    			TextChannel channel = (TextChannel) GameDataLoader.discord.getChannelById("DISCORD CLAN CHANNEL ID").get();
    			String ts = "";	        
    	        ts = ts + player.getUsername()+": ";
    			channel.sendMessage("**"+ts+"**"+"`"+paramString+"`");
    		}





    If you have any questions feel free to post them below, I will try my best to answer. If there are any bugs or other problems like missed imports please let me know so I can update the guide. If you want me to do this with another source base, comment the link to the downloads section post of the source (I won't do anything that doesn't have many downloads just to be safe of viruses and such)

    What you're adding
    Spoiler for What you're adding:

    Attached image
    Attached image


    If you want me to do this for you
    Last edited by Pharaoh; 05-21-2020 at 11:31 AM.
    Reply With Quote  
     

  2. Thankful users:


  3. #2  
    Donator

    i dds you's Avatar
    Join Date
    Jun 2013
    Posts
    831
    Thanks given
    678
    Thanks received
    160
    Rep Power
    92
    Thanks for sharing man, this is pretty cool. I'm going to try it out

    Reply With Quote  
     

  4. #3  
    #1 Interface Services

    Herb's Avatar
    Join Date
    Nov 2015
    Posts
    587
    Thanks given
    181
    Thanks received
    705
    Rep Power
    4387
    Credits for using my name?
    Looks dank!
    Spoiler for signature:
    Reply With Quote  
     

  5. Thankful user:


  6. #4  
    RSPS Youtuber at youtube.com/nesrsps

    Nes's Avatar
    Join Date
    Aug 2014
    Age
    25
    Posts
    504
    Thanks given
    205
    Thanks received
    310
    Rep Power
    1271
    This is pretty cool haha!
    Attached image
    Reply With Quote  
     

  7. #5  
    Donator


    Join Date
    Nov 2012
    Age
    27
    Posts
    165
    Thanks given
    91
    Thanks received
    80
    Rep Power
    160
    Quote Originally Posted by Herb View Post
    Credits for using my name?
    Looks dank!
    Lol, I re-used a bot I had made for a weed-related minecraft server I was dev on for a little while cuz I didn't feel like making a new one

    Quote Originally Posted by Nes View Post
    This is pretty cool haha!
    Thanks! Glad you like it

    Quote Originally Posted by i dds you View Post
    Thanks for sharing man, this is pretty cool. I'm going to try it out
    No problem and good luck!
    Reply With Quote  
     

  8. Thankful user:


  9. #6  
    AleronPS


    Join Date
    Dec 2017
    Posts
    93
    Thanks given
    99
    Thanks received
    10
    Rep Power
    73
    A HUGE Vouch for Pharaoh, easy to setup, easy to read. Definitely recommending this!
    Yours Sincerely,
    Eliyahu | Aleron

    Reply With Quote  
     

  10. #7  
    Donator

    i dds you's Avatar
    Join Date
    Jun 2013
    Posts
    831
    Thanks given
    678
    Thanks received
    160
    Rep Power
    92
    Big thanks and vouch for this guy! I got a little confused over Discord ID's and he was kind enough to point me back on the right path, Works really well

    Attached image

    Reply With Quote  
     


Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


User Tag List

Similar Threads

  1. Replies: 0
    Last Post: 11-02-2018, 02:32 AM
  2. Basic Discord Bot
    By _Naitsirhc in forum Tutorials
    Replies: 7
    Last Post: 05-07-2018, 04:07 AM
  3. This is basically my first botted account.;0
    By Pj then Pk in forum RuneScape Underground
    Replies: 13
    Last Post: 02-24-2009, 04:45 AM
  4. [tut]Basic Quick Chat[tut]
    By jabbah in forum Tutorials
    Replies: 7
    Last Post: 01-28-2009, 04:32 PM
  5. [508]!@!~Basic Private Chat~!@![508]
    By mikelmao in forum Tutorials
    Replies: 24
    Last Post: 11-23-2008, 03:11 AM
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •