### Basic Javacord Discord Bot Example Source: https://javacord.org/wiki/getting-started/setup/eclipse-maven This Java code provides a minimal working example of a Javacord Discord bot. It initializes the `DiscordApi` with a provided token, sets up a message listener to respond with 'Pong!' when a user sends '!ping', and prints the bot's invite URL to the console for easy sharing. ```Java package com.github.yourname.myfirstbot; import org.javacord.api.DiscordApi; import org.javacord.api.DiscordApiBuilder; public class Main { public static void main(String[] args) { // Insert your bot's token here String token = "your token"; DiscordApi api = new DiscordApiBuilder().setToken(token).login().join(); // Add a listener which answers with "Pong!" if someone writes "!ping" api.addMessageCreateListener(event -> { if (event.getMessageContent().equalsIgnoreCase("!ping")) { event.getChannel().sendMessage("Pong!"); } }); // Print the invite url of your bot System.out.println("You can invite the bot by using the following url: " + api.createBotInvite()); } } ``` -------------------------------- ### Basic Javacord Discord Bot Example Source: https://javacord.org/wiki/getting-started/setup/intellij-maven This Java code demonstrates a simple Javacord bot that logs in using a provided token and responds with 'Pong!' when a user sends '!ping' in any channel the bot can see. It also prints the bot's invite URL to the console, allowing easy sharing and addition to Discord servers. ```Java package com.github.yourname; import org.javacord.api.DiscordApi; import org.javacord.api.DiscordApiBuilder; public class Main { public static void main(String[] args) { // Insert your bot's token here String token = "your token"; DiscordApi api = new DiscordApiBuilder().setToken(token).login().join(); // Add a listener which answers with "Pong!" if someone writes "!ping" api.addMessageCreateListener(event -> { if (event.getMessageContent().equalsIgnoreCase("!ping")) { event.getChannel().sendMessage("Pong!"); } }); // Print the invite url of your bot System.out.println("You can invite the bot by using the following url: " + api.createBotInvite()); } } ``` -------------------------------- ### Add Javacord Snapshot Dependency Source: https://javacord.org/wiki/getting-started/download-installation Instructions for integrating the latest development (snapshot) version of the Javacord library. This setup is useful for accessing new features or bug fixes before they are officially released, requiring the addition of a specific snapshot repository. ```Groovy repositories { maven { url "https://oss.sonatype.org/content/repositories/snapshots/" } } dependencies { implementation 'org.javacord:javacord:$latest-snapshot-version' } ``` ```XML snapshots-repo https://oss.sonatype.org/content/repositories/snapshots/ org.javacord javacord $latest-snapshot-version pom ``` ```Scala resolvers += "snapshots-repo" at "https://oss.sonatype.org/content/repositories/snapshots/" libraryDependencies ++= Seq("org.javacord" % "javacord" % "$latest-snapshot-version") ``` -------------------------------- ### Ineffective Support Question Formats Source: https://javacord.org/wiki/getting-started/faq These examples demonstrate unhelpful ways to ask for technical support, lacking crucial context and details necessary for effective troubleshooting. ```Plaintext Why is my code not working? //Code ``` ```Plaintext Why am I getting Exception X? ``` -------------------------------- ### Add Log4j Core Logging Dependency Source: https://javacord.org/wiki/getting-started/download-installation Provides code examples for declaring the Log4j Core dependency in different Java build systems. This dependency enables advanced logging features like custom log formats, diverse log targets (console, file), and granular log level control per class. ```Groovy dependencies { runtimeOnly 'org.apache.logging.log4j:log4j-core:2.17.0' } ``` ```XML org.apache.logging.log4j log4j-core 2.17.0 ``` ```Scala libraryDependencies ++= Seq("org.apache.logging.log4j" % "log4j-core" % "2.17.0") ``` -------------------------------- ### Respond to AutoComplete Interaction (Javacord) Source: https://javacord.org/wiki/basic-tutorials/interactions/responding Provides an example of how to respond to an autocomplete interaction triggered by a slash command. It shows how to offer a list of predefined choices to the user as they type. ```Java api.addAutocompleteCreateListener(event -> { event.getAutocompleteInteraction() .respondWithChoices(Arrays.asList( SlashCommandOptionChoice.create("one", 1), SlashCommandOptionChoice.create("two", 2)) ); }); ``` -------------------------------- ### Example Javacord Fallback Logger Output Format Source: https://javacord.org/wiki/basic-tutorials/logger-config Illustrates the standard format of a log line generated by Javacord's fallback logger, showing components like timestamp, log level, logger name, message, and thread context (e.g., shard number). ```Log Output