in , ,

Creating An Android App To Host Discord Bots Easily

Well I created an android app to host discord bots easily. just enter your token and click on host. It will use your android to host your android bot 24/7. I’ll show you the basic structure how you can do it.

Steps To Create An Android App To Host Discord Bots

In order to this you must have a basic understanding of Android Studio and JAVA.

Open your android studio and create a new empty project.

Android App To Host Discord Bots

Now open build.gradle and these things in buildscript and allprojects

  // add just mavenCentral
buildscript {
    repositories {
        google()
        jcenter()
        mavenCentral()
    }
  // add just mavenCentral
allprojects {
    repositories {
        google()
        jcenter()
        mavenCentral()
    }
}

then go to your app gradle and add these libraries.

    implementation "androidx.multidex:multidex:2.0.1"
    implementation 'org.javacord:javacord:3.1.2'

You have to enable the multidex in default config under app gradle

    //only copy - paste multiDexEnabled true in default config
    defaultConfig {
        multiDexEnabled true
    }

Now lets customize our activity-main.xml for UI of our app.

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <TextView
        android:id="@+id/textView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="My Bot Builder"
        android:textSize="30sp"
        android:textStyle="bold"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintHorizontal_bias="0.458"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.21" />

    <EditText
        android:id="@+id/userToken"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:ems="10"
        android:hint="Token"
        android:inputType="textPersonName"
        android:textStyle="bold"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/textView"
        app:layout_constraintVertical_bias="0.113" />

    <Button
        android:id="@+id/hostButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="HOST"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.498"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/userToken"
        app:layout_constraintVertical_bias="0.204" />

</androidx.constraintlayout.widget.ConstraintLayout>

This is how the UI of the app will look nothing so special.

App UI Preview

Ok now we will have to create backend so that we can make this app host our bot using token.

Lets Go Our Main-Activity.java and do some coding. we are using javacord library to interact with discord API.

public class MainActivity extends AppCompatActivity {
    Button hostButton;
    EditText userToken;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        hostButton = findViewById(R.id.hostButton);
        userToken = findViewById(R.id.userToken);
        hostButton.setOnClickListener(new View.OnClickListener() {
            @RequiresApi(api = Build.VERSION_CODES.N)
            @Override
            public void onClick(View v) {
                //fetching token from editable Text on app
                String token = userToken.getText().toString();
                //making bot online using token
                DiscordApi api = new DiscordApiBuilder().setToken(token).login().join();
                //command
                api.addMessageCreateListener(event -> {
                    if (event.getMessageContent().equalsIgnoreCase("!ping")) {
                        event.getChannel().sendMessage("Pong!").thenAccept(message -> {
                            // Attach a listener directly to the message
                            message.addReactionAddListener(reactionEvent -> {
                                if (reactionEvent.getEmoji().equalsEmoji("👎")) {
                                    reactionEvent.deleteMessage();
                                }
                            }).removeAfter(30, TimeUnit.MINUTES);
                        });
                    }
                });
            }
        });
    }
}

And that’s it but keep in mind this app will only work for android 7.0 [API 24+] and above.

Also Read: How To Fix ADB Has Stopped Working in Android Studio

SO>SOURCE CODE

GITHUB

Related Posts

Written by Senpai

"This may be a virtual world,but I feel more alive here then in the real world"

Leave a Reply

One Comment