Jump to content


[Python] Discord Global Chat

Recommended Posts

Hi everyone,


I just wanted to share my second official Python project which is another Discord bot using the Discord.py wrapper (similar to this project I posted a few minutes ago). This is also being used in the new Discord community/brand @Bue. and I are working on (I will not share the community name here and it is nothing like GFL). GFL may be interested in a project like this, though. @JGuary55 and I were discussing this idea a couple days ago and I decided to just make it then, lol.


This Discord bot "links" channels together from different guilds/servers (one channel per guild/server) and makes it act as a global chat. When somebody submits a message in a global/linked channel, it will broadcast that message via a Discord Webhook to all other global/linked channels in other guilds/servers and make the Webhook message's username the user's display name on that current server and also use the user's avatar.





Note - When you see a message with "Bot" afterwards, that indicates a message from another guild/server since it's the Webhook.



A Discord bot that allows for global chat between Discord servers in certain channels.


The Discord.py package is required in order to use this bot. You may install this via the following command.


python3 -m pip install -U discord.py

Command Line Usage
You may specify the settings JSON (used for the bot token, etc) and the SQLite DB location within the command line. The default settings location is /etc/dgc/settings.json and the default SQLite DB location is /etc/dgc/dgc.db.


The following are examples of how to set these in the program.


python3 src/main.py cfg=/home/cdeacon/settings.json sqlite=/home/cdeacon/dgc.db

The config file is in JSON format and the following keys are supported.


  • BotToken - The Discord bot token. Please retrieve this from the Discord Developers page for your bot.
  • BotMsgStayTime - When the bot replies to a command in a text channel, delete the bot message this many seconds after (default - 10.0 seconds).
  • UpdateTime - How often to update the channel and web hook URL cache in seconds (default - 60.0 seconds).


Bot Commands
The command prefix is !. You must execute these commands inside of a text channel of the guild you want to modify. You must also be an administrator in order to use these commands.



!dgc_linkchannel <channel ID>

Adds a channel to the linked global chat. If the channel ID is left blank, it will choose the channel the message was sent in.



!dgc_unlinkchannel <channel ID>

Unlinks a channel to the linked global chat.



!dgc_updatehook <webhook URL>

Updates the web hook that messages send to within the current guild. This must be pointed towards the correct channel ID set with dgc_linkchannel.


You may use make install within this directory to create the /etc/dgc/ directory and copy settings.json.example to /etc/dgc/settings.json. Please configure the settings.json file to your needs.


Other than that, the needed SQLite tables are created if they don't exist when the Python program is started. However, if need to be, here is the current table structure.


CREATE TABLE IF NOT EXISTS `channels` (guildid integer PRIMARY KEY, channelid integer, webhookurl text)

As of right now, you'll want to use python3 against the src/main.py file. Something like the following should work.


python3 src/main.py

If there's a better way to handle this, please let me know.




GitHub Repository

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...