Thread: Discord Bot Base - Any Revision, Any Base.

Results 1 to 4 of 4
  1. #1 Discord Bot Base - Any Revision, Any Base. 
    Extreme Donator

    Patrity's Avatar
    Join Date
    Jul 2008
    Age
    26
    Posts
    733
    Thanks given
    36
    Thanks received
    110
    Rep Power
    111
    This bot uses the JavaCord library. I have used JavaCord and Discord4J and much prefer JavaCord simply because it is more object oriented and queues messages for you, not to send too many messages and potentially have discord ban your bot.

    All documentation regarding Javacord can be found here: [Only registered and activated users can see links. ]

    You will need to include this dependency:

    Gradle:
    Code:
    repositories { mavenCentral() }
    dependencies { implementation 'org.javacord:javacord:3.0.4' }
    Maven:
    Code:
    <dependency>
        <groupId>org.javacord</groupId>
        <artifactId>javacord</artifactId>
        <version>3.0.4</version>
        <type>pom</type>
    </dependency>
    Create a new class:
    Spoiler for Code:
    Code:
    import java.awt.Color;
    import java.util.List;
    import java.util.Optional;
    
    import org.javacord.api.DiscordApi;
    import org.javacord.api.DiscordApiBuilder;
    import org.javacord.api.entity.channel.TextChannel;
    import org.javacord.api.entity.message.MessageBuilder;
    import org.javacord.api.util.logging.ExceptionLogger;
    
    
    /**
     * @author Patrity || https://www.rune-server.ee/members/patrity/
     */
    
    public class JavaCord {
    
    	private static String token = "INSERT DISCORD BOT TOKEN HERE";
    
    	private static String serverName = "YOUR SERVER NAME";
    	
    	private static DiscordApi api = null;
    
    	public static void init() {
    		new DiscordApiBuilder().setToken(token).login().thenAccept(api -> {
    			JavaCord.api = api;
    			System.out.println("You can invite the bot by using the following url: " + api.createBotInvite());
    			sendMessage("general", serverName+" is now online!");
    			api.addMessageCreateListener(event -> {
    				
    				if (event.getMessageContent().equalsIgnoreCase("::players")) {
    					int online = (int)PlayerHandler.getRealPlayerCount();
    					event.getChannel().sendMessage("Players currently online: "+online);
    				}				
    				
    				if (event.getMessageContent().equalsIgnoreCase("::online")) {
    					event.getChannel().sendMessage(":tada: "+serverName+" is Online! :tada:");
    				}
    				
    				
    				if (event.getMessageContent().startsWith("::movehome")) {
    					if (event.getMessageAuthor().isServerAdmin()) {
    						System.out.println("perms");
    						String target = event.getMessageContent().replace("::movehome ", "");
    						Optional<Player> optionalPlayer = PlayerHandler.getOptionalPlayer(target);
    						if (optionalPlayer.isPresent()) {
    							Player c2 = optionalPlayer.get();
    							c2.setX(3357);
    							c2.setY(9313);
    							c2.setHeight(0);
    							c2.setNeedsPlacement(true);
    							event.getChannel().sendMessage("You have teleported " + c2.playerName + " to home.");
    							c2.sendMessage("You have been teleported home by " + event.getMessageAuthor().getDisplayName() + ".");
    						} else { 
    							event.getChannel().sendMessage("Player is not online!");
    						}
    					} else {
    						event.getChannel().sendMessage("You do not have permission to preform this command");
    					}
    				}		
    				
    				if (event.getMessageContent().startsWith("::kick")) {
    					if (event.getMessageAuthor().isServerAdmin()) {
    						String target = event.getMessageContent().replace("::kick ", "");
    						Optional<Player> optionalPlayer = PlayerHandler.getOptionalPlayer(target);
    						if (optionalPlayer.isPresent()) {
    							Player c2 = optionalPlayer.get();
    							if (World.getWorld().getMultiplayerSessionListener().inAnySession(c2)) {
    								event.getChannel().sendMessage("The player is in a trade, or duel. You cannot do this at this time.");
    								return;
    							}
    							c2.outStream.writePacketHeader(109);
    							CycleEventHandler.getSingleton().stopEvents(c2);
    							c2.properLogout = true;			
    							c2.disconnected = true;
    							c2.logoutDelay = Long.MAX_VALUE;
    							event.getChannel().sendMessage("Successfully kicked: " + c2.playerName + ".");
    							ConnectedFrom.addConnectedFrom(c2, c2.connectedFrom);
    						} else { 
    							event.getChannel().sendMessage("Player is not online!");
    						}
    					} else {
    						event.getChannel().sendMessage("You do not have permission to preform this command");
    					}
    				}
    				
    			});
    		})
    				// Log any exceptions that happened
    				.exceptionally(ExceptionLogger.get());
    	}
    
    	public static void sendMessage(String channel, String msg) {
    		if (World.localWorld) {
    			return;
    		}
    		try {
    			new MessageBuilder()
    			.append(msg)
    			.send((TextChannel) api.getTextChannelsByNameIgnoreCase(channel).toArray()[0]);
    		} catch (Exception e) {
    			e.printStackTrace();
    		}
    	}	
    
    }


    With this class now in your server, you will need to initialize the class to run on server start, that can be done with:
    Code:
    JavaCord.init();
    So, looking back at the JavaCord class you created, you will need to make some changes depending on your base. The commands can use the same means that your in game commands use, for example the kick command. The code in the above kick command can be replaced with the code from what your server currently uses. The potential is really endless.
    Please be careful with these commands and be sure to check for discord admin where required.
    There is also other checks that JavaCord supports such as by Discord role, and Discord user ID. Please refer to the github page.

    Now let's set up our Bot.
    Follow this link: [Only registered and activated users can see links. ]
    Set up a new application

    Give your bot a name and a profile picture (these only appear in your developer window)


    Head to the Bot tab of the application settings
    Name your bot and give it a picture (This is what will appear in your server when the bot speaks)
    Reveal the token on this page and copy it.


    Paste this token in your JavaCord class we created earlier and run your server.

    After the bot initializes it will print out a URL in your server console. Navigate to that url to invite the bot to your discord server.
    You're done!


    Adding Triggered Messages Throughout Your Server:
    There is a method created in this class to easily send messages on events from within the server, whether you want to send logs, drops, events, kills or whatever.
    simply call:
    Code:
    JavaCord.sendMessage("channel", "msg")
    For example when a rare drop is announced in game, you can add this call immediately after the in-game announcement to also announce rare drops in discord.



    Some Tips:
    1. Do not give the bot administration or any other permissions of the sort. If you want to use a bot for user management or other features, use Dyno or MEE6. With this client token being in your source, if your source gets leaked so does the discord token. This can lead to your entire discord server being griefed or deleted.
    2. When adding new commands, be sure that it is checking for the proper discord permissions, such as for kick or ban commands if you plan on adding those to this bot.
    3. READ THE JAVACORD API AND JOIN THEIR DISCORD. There is many more capabilities with this bot such as creating embeds. The community is helpful, but will not spoon-feed you.



    Good luck!
    Free map releases: [Only registered and activated users can see links. ]


    [Only registered and activated users can see links. ]
    Reply With Quote  
     

  2. Thankful user:


  3. #2  
    ✥Blade Owner✥

    TeJay's Avatar
    Join Date
    Jul 2017
    Posts
    507
    Thanks given
    133
    Thanks received
    174
    Rep Power
    769
    Great job Pat!
    [Only registered and activated users can see links. ]

    Spoiler for Services:
    [Only registered and activated users can see links. ]
    Reply With Quote  
     

  4. #3  
    Extreme Donator

    Patrity's Avatar
    Join Date
    Jul 2008
    Age
    26
    Posts
    733
    Thanks given
    36
    Thanks received
    110
    Rep Power
    111
    Quote Originally Posted by TeJay View Post
    Great job Pat!
    Thank ya, buddy!
    Free map releases: [Only registered and activated users can see links. ]


    [Only registered and activated users can see links. ]
    Reply With Quote  
     

  5. #4  
    OWNER @ BOFA (Now Hiring)
    Mr Bill's Avatar
    Join Date
    May 2010
    Posts
    511
    Thanks given
    14
    Thanks received
    24
    Rep Power
    19
    What a legend, thanks
    Reply With Quote  
     


Thread Information
Users Browsing this Thread

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

Similar Threads

  1. [718] [Any Revision]AIO Discord Bot
    By Cody_ in forum Projects
    Replies: 7
    Last Post: 06-08-2019, 07:07 AM
  2. Bob's RSPS Services and Content - Any Revision/Base
    By bobismyname in forum Selling
    Replies: 20
    Last Post: 05-19-2017, 02:03 PM
  3. Any Decent Pk Bases?
    By GreekO in forum Requests
    Replies: 0
    Last Post: 08-02-2013, 01:56 AM
  4. Replies: 2
    Last Post: 03-11-2013, 03:47 AM
  5. Any custom minigame base [INCLUDES USE OF TIMERS]
    By Polaroid in forum Tutorials
    Replies: 24
    Last Post: 10-18-2010, 02:24 PM
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •