This bot is used to obtain the public ip address of the host machine on which this bot is deployed. This is useful if a service is hosted in a private network and you want to access it from outside the network. In particular, this bot is used to obtain the public ip address of a Raspberry Pi that is hosting a Minecraft server.
This bot can be used in two ways. The first way is the plain usage of node js. The second way is to use docker.
In order to successfully run the bot with plain node js, you need to have node and npm installed in the first place. Specifically, the node version must be v16.9.0 or higher.
Install the dependencies with npm install.
It is necessary to create a file called .env in the root directory of the project, similar to the .envSample file.
Register the Slash-Commands:
$ node deploy-commands.jsStart the bot:
$ node index.jsIt es recommended to use a process manager like pm2 to run the bot in the background.
The bot can easily be started in a docker container. The docker image is available on Docker Hub.
$ docker run -d --name discord-ip-bot -e BOTTOKEN=<your-token> -e GUILD_ID=<guild-id> -e CLIENT_ID=<client-id> jaypi4c/discord-ip-bot(The container does not run the deploy-commands.js script. Therefore, the commands have to be registered manually. Maybe in the future I will add a script that registers the commands automatically.)
The GUILD_ID is the server's ID, which can be obtained directly from discord. For the BOTTOKEN and the CLIENT_ID you must visit the Discord Developer Portal.
Furthermort, it is possible to clear all registered commands with the CLEAR_COMMANDS variable. This is useful if you want to change the commands. The default value is false. (But in all honesty, the docker version does not run the deploy-commands.js script, so you have to clear the commands manually.)
It is requiered to have docker and docker-compose installed on the Raspberry Pi.
To run the bot and the Minecraft server on the same Raspberry Pi, you can create a docker-compose.yml file with the following content:
services:
minecraft:
image: itzg/minecraft-server:java17-alpine
container_name: minecraft
ports:
- "12345:25565"
environment:
EULA: "FALSE"
VERSION: "1.7.10"
restart: unless-stopped
volumes:
- ./minecraft-data:/data
ip-bot:
image: jaypi4c/discord-ip-bot:1.4.1
container_name: discord-ip-bot
restart: unless-stopped
environment:
BOTTOKEN: <your-token>
CLIENT_ID: <client-id>
GUILD_ID: <guild-id>
CLEAR_COMMANDS: "false"
SERVER_PORT: 12345
MAP_PORT: 12345
MAP_HTTPS: false
WAIT_MESSAGES: '["test''s"]'
DISPLAY_MESSAGES: '["test"]'The tokens and IDs must be changed respectivly. The minecraft-data folder is used to store the world data of the Minecraft server. Also it is necessary to accept the EULA of the Minecraft server. This can be done by setting the EULA variable to TRUE. For more information about the minecraft server image, visit the GitHub repository of the image.
You can run the bot and the Minecraft server with the following command in the same directory as the docker-compose.yml file:
$ docker-compose up -dTo enable IPv6 support for the Discord IP Bot when using Docker Compose, you need to ensure that your Docker daemon (/etc/docker/daemon.json needs to have {"ipv6": true} inside) is configured to support IPv6 and that you have an external IPv6-enabled network created (docker network create --ipv6 ipv6net). With this done, you can add the following lines to the ip-bot service in your docker-compose.yml file:
environment:
ENABLE_IPV6: "true"
networks:
- ipv6net
networks:
ipv6net:
external: trueThis bot is based on the Guide of the Discord.js library. Additionally, the Video series of Daniel Shiffman is very helpful.