Skip to content

Commit 637d2cc

Browse files
committed
Added discords and discord.bots.gg APIs
- push guild count to these APIs
1 parent 0f3859c commit 637d2cc

2 files changed

Lines changed: 25 additions & 12 deletions

File tree

README.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,12 @@ Counting and guild data is saved to a JSON database, eliminating the need for ex
6666
For added security and to comply by Discord's ToS, create a .env file in the root directory of the ChadCounting bot folder (where bot.py is located). This file serves as the designated location to securely store bot tokens. To add your Discord bot tokens, follow the example below:
6767
```
6868
# .env
69-
DISCORD_TOKEN=your_discord_bot_token
70-
DEV_TOKEN=your_discord_dev_bot_token
71-
DISCORDBOTLIST_TOKEN=your_discordbotlist_token
72-
TOPGG_TOKEN=your_topgg_token
69+
DISCORD_TOKEN=token_here
70+
DEV_TOKEN=token_here
71+
DISCORDBOTLIST_TOKEN=token_here
72+
TOPGG_TOKEN=token_here
73+
DISCORDS_TOKEN=token_here
74+
DISCORDBOTSGG_TOKEN=token_here
7375
```
7476

7577
### Versioning

bot.py

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,22 @@
2929

3030
# Initialize variables and load environment tables
3131
load_dotenv()
32-
DISCORD_TOKEN = os.getenv("DISCORD_TOKEN") # Normal ChadCounting token
32+
PROD_TOKEN = os.getenv("PROD_TOKEN") # Normal ChadCounting token
3333
DEV_TOKEN = os.getenv("DEV_TOKEN") # ChadCounting Dev bot account token
34-
DISCORDBOTLIST_TOKEN = os.getenv("DISCORDBOTLIST_TOKEN") # For using the https://discordbotlist.com API
35-
TOPGG_TOKEN = os.getenv("TOPGG_TOKEN") # For using the https://top.gg API
3634
guild_data = {} # Global variable for database
37-
bot_version = "1.0.1-indev"
35+
bot_version = "1.0.1"
3836
chadcounting_color = 0xCA93FF # Color of the embeds
3937
image_gigachad = "https://github.com/Gitfoe/ChadCounting/blob/main/gigachad.jpeg?raw=true"
38+
39+
# Initialize API tokens and URIs
40+
DISCORDBOTLIST_TOKEN = os.getenv("DISCORDBOTLIST_TOKEN")
41+
TOPGG_TOKEN = os.getenv("TOPGG_TOKEN")
42+
DISCORDS_TOKEN = os.getenv("DISCORDS_TOKEN")
43+
DISCORDBOTSGG_TOKEN = os.getenv("DISCORDBOTSGG_TOKEN")
4044
api_discordbotslist = "https://discordbotlist.com/api/v1/bots/chadcounting"
4145
api_topgg = "https://top.gg/api/bots/1066081427935993886"
46+
api_discords = "https://discords.com/bots/api/bot/1066081427935993886"
47+
api_discordbotsgg = "https://discord.bots.gg/api/v1/bots/1066081427935993886"
4248

4349
# Initialize bot and intents
4450
intents = discord.Intents.default()
@@ -713,6 +719,7 @@ def __init__(self):
713719
{"label": "More information", "url": "https://github.com/Gitfoe/ChadCounting", "emoji": "ℹ️"},
714720
{"label": "Vote on top.gg", "url": "https://top.gg/bot/1066081427935993886/vote", "emoji": "⬆️"},
715721
{"label": "Vote on discordbotlist", "url": "https://discordbotlist.com/bots/chadcounting/upvote", "emoji": "⬆️"},
722+
{"label": "Vote on discords", "url": "https://discordbotlist.com/bots/chadcounting/upvote", "emoji": "⬆️"},
716723
]
717724
for button in buttons:
718725
self.add_item(Button(**button))
@@ -1206,10 +1213,10 @@ def discordbotlist_api_authorization_header():
12061213
"Content-Type": "application/json"
12071214
}
12081215

1209-
def topgg_api_authorization_header():
1216+
def generic_api_authorization_header(token):
12101217
"""Base headers for the Top.GG API."""
12111218
return {
1212-
"Authorization": TOPGG_TOKEN,
1219+
"Authorization": token,
12131220
"Content-Type": "application/json"
12141221
}
12151222

@@ -1229,9 +1236,13 @@ def push_guilds_count_to_all_bot_websites():
12291236
"""Pushes the current guild count to all bot websites configured."""
12301237
if check_dev_disable_apis(push_guilds_count_to_all_bot_websites.__name__): return
12311238
discordbotlist_headers = discordbotlist_api_authorization_header()
1232-
topgg_headers = topgg_api_authorization_header()
1239+
topgg_headers = generic_api_authorization_header(TOPGG_TOKEN)
1240+
discords_headers = generic_api_authorization_header(DISCORDS_TOKEN)
1241+
discordbotsgg_headers = generic_api_authorization_header(DISCORDBOTSGG_TOKEN)
12331242
push_guilds_count_to_bot_website(f"{api_discordbotslist}/stats", "guilds", discordbotlist_headers)
12341243
push_guilds_count_to_bot_website(f"{api_topgg}/stats", "server_count", topgg_headers)
1244+
push_guilds_count_to_bot_website(api_discords, "server_count", discords_headers)
1245+
push_guilds_count_to_bot_website(f"{api_discordbotsgg}/stats", "guildCount", discordbotsgg_headers)
12351246

12361247
def push_guilds_count_to_bot_website(url, payload_string, headers):
12371248
"""Sends the number of guilds via the API."""
@@ -1240,5 +1251,5 @@ def push_guilds_count_to_bot_website(url, payload_string, headers):
12401251
print(f"[{datetime.now()}] {push_guilds_count_to_bot_website.__name__}: {url} API response {response.status_code}.")
12411252
#endregion
12421253

1243-
bot.run(DEV_TOKEN)
1254+
bot.run(PROD_TOKEN)
12441255
# Coded by https://github.com/Gitfoe

0 commit comments

Comments
 (0)