Skip to main content
  1. Projects/

Discord Bot - Voice Channel Extras

·5 mins· 0 · 0 ·
Projects Current
Idea / Function>

Idea / Function

In a conversation, the desire for a ping possibility, as known from Teamspeak, was raised, which does not exist so in Discord. Discord supports a function called “Mentions”, but these are not comparable to a nudge or a ping.

In the future, a group of users will automatically receive a ping message as soon as a user enters a certain voice channel.

There was also talk of minimizing voice channels, since normal voice channels do not scale with demand and there are often too many or too few of them. It would be a good idea to automatically create new channels when the existing ones are full.

The lobby function has already been implemented by various other bots. I have oriented myself to the following implementation (orientation => function similar, code is completely independent) Auto Voice Channels

Commands>

Commands

Create a relation between the ping messages and the channel, which triggers them on join
/ping channel {name} [{removeFlag}]

Set the Role for the Notifications
/ping role {name} [{removeFlag}]

Optional Flag: {removeFlag} for removing the channel or role. It schould be one of the follwing values: true or false.

Show some brief informations about the ping settings
/ping info

Show a summary of informations for the bot
/info

Mute the notifications that will possible sent to you
/mute

Create a Lobby, will be replicated on join
/lobby create {channel}

Remove the Lobby, the tempory channels will be removed after all participants leave
/lobby remove {channel}

Implementation>

Implementation

I used the libary JDA (Java Discord API) for creating the bot.

Java implementation>

Java implementation

I will describe in the following sections some parts of the implementation. I won’t share the source code completly.

Ping Function>

Ping Function

The Ping function takes to parameters, first is the IDs for the channel and second the IDs of the notification roles. On each join of a member to a voice channel, the function will be called. This event checks if the current channel is part of the watched channels array. After that it initate the notification process with the notfication roles, that matches these pings. All Members of this notification role are notified.

AudioChannelUnion joined = event.getChannelJoined();
AudioChannelUnion left = event.getChannelLeft();
if (joined != null) {
    if (config.isDebug()) log.debug("User {} joined channel {}", event.getMember().getEffectiveName(), joined.getName());
    pingListener.joined(event, guildConfig, joined);
    lobbyListener.joined(event, guildConfig, joined);
}
if (left != null) {
    if (config.isDebug()) log.debug("User {} left channel {}", event.getMember().getEffectiveName(), left.getName());
    lobbyListener.left(event, guildConfig, left);
}
Lobby Function>

Lobby Function

As already seen in the ping function in the code, a LobbyListener is also initiated there. This one controls the automatic creation of new channels when entering the lobby channel. The name is first replicated and then adapted to the currently most played game of the participants.

Here is the function that determines the most played activity in the voice channel. This is called when the activity is entered, left or changed.

I still have to test if this amount might exceed the rate limits of Discord.

private String getMaxActivity(VoiceChannel primary) {
        Map<String, Long> groupedActivities = primary.getMembers()
                .stream().flatMap(member -> member.getActivities().stream())
                .collect(Collectors.groupingBy(Activity::getName, Collectors.counting()));
        return groupedActivities.entrySet().stream()
                .filter(stringLongEntry -> !stringLongEntry.getKey().equals("Custom Status"))
                .sorted(Map.Entry.comparingByValue())
                .map(Map.Entry::getKey)
                .findFirst().orElse(primary.getName());
}
Hosting with Docker>

Hosting with Docker

To make hosting as easy as possible and also save me work when deploying, I decided to use a Docker image. This is structured as follows:

FROM openjdk:18
COPY /target/VoicePingChannel-0.1.0.jar /usr/src/VPCBot/VoicePingChannel-0.1.0-proguard.jar
WORKDIR /usr/src/VPCBot/
VOLUME /usr/src/VPCBot/config/
LABEL version="1.0"
LABEL description="I am a Discord Bot, which provides automatic Lobbys and Pings."
ENV BOT_TOKEN=""
CMD ["java", "-jar", "VoicePingChannel-0.1.0-proguard.jar", "--config", "./config/config.json"]

The image is based on OpenJDK 18 and copies the built bot instance into the working directory as a first step. This built instance was made unreadable with Proguard (Obfuscating).

Then the workdir, a volume and labels are created. The bot token can be passed directly as an environment variable as the only configuration variable. The rest must be adjusted in the volume in the configuration file.

Finally the start command is defined.

Try out>

Try out

The bot can be tried out via the link below. I reserve the right to block the use of the bot if the functions are not properly used or exploited.

An own hosting possible to get a better performance.

A distribution, duplication or modification of the bot, is not allowed. Copyright law applies accordingly. In case of self-hosting it is mandatory to add a reference to me as the author in the form of a link. An offence has appropriate legal consequences.

A use of the bot and a hosting is free of charge under compliance with the rules.

If you are interested in more, feel free to contact me.
Invite the Bot
Support>

Support

I will provide Support on my own discord server. ⇨ Link

Feedback>

Feedback

I’m happy with all feedback you have. I will try to make the bot better.

Photo taken by Arek Socha on Pixabay

Todos:>

Todos:

  • Introducing Sharding for better stability and more servers
  • Making the ping role relate to the channel
  • Notify only members which are online (DnD and Away may be ignored)
  • Sharding System should be tested and monitored


Niklas (ModdyLP)
Author
Niklas (ModdyLP)
Software Developer and Dream Creator