Skip to content

Commit

Permalink
Migration on nextcord
Browse files Browse the repository at this point in the history
  • Loading branch information
SuperKali committed Sep 5, 2022
1 parent 4c6cc27 commit 756b406
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 20 deletions.
16 changes: 8 additions & 8 deletions cogs/commands.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import discord
import nextcord
import json
from discord.ext import commands
from nextcord.ext import commands

class Commands(commands.Cog):
def __init__(self, client):
Expand All @@ -16,10 +16,10 @@ async def createstatusmsg(self, ctx):
with open('data.json') as data:
self.data = json.load(data)

embed = discord.Embed(
embed = nextcord.Embed(
title="MCStatusBot Configured 🎉",
description=f"This message will be updated with the status message automatically.",
color=discord.Colour.blue())
color=nextcord.Colour.blue())

message = await ctx.send(embed=embed)
await ctx.message.delete()
Expand All @@ -34,14 +34,14 @@ async def createstatusmsg(self, ctx):

@commands.command()
async def help(self, ctx):
embed = discord.Embed(
embed = nextcord.Embed(
title="Commands of MCStatusBot",
description=f"{self.config['bot_prefix']}createstatusmsg - allow you to create a message where will be configured the status message.",
color=discord.Colour.dark_blue())
color=nextcord.Colour.dark_blue())

embed.set_footer(text="Bot developed by SuperKali#8716")

await ctx.send(embed=embed)

def setup(client):
client.add_cog(Commands(client))
async def setup(client):
client.add_cog(Commands(client))
22 changes: 11 additions & 11 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
import discord
import asyncio
import nextcord
import time
import json
import os

from discord.ext import commands
from nextcord.ext import commands
from mcstatus import JavaServer, BedrockServer
from colorama import init, Fore, Style, Back
from apscheduler.schedulers.asyncio import AsyncIOScheduler

with open('config.json') as config_file:
config = json.load(config_file)

client = commands.Bot(command_prefix=config["bot_prefix"], help_command=None, intents=discord.Intents.all())
client = commands.Bot(command_prefix=config["bot_prefix"], help_command=None, intents=nextcord.Intents.all())

bot_token = config['bot_token']

count_all_servers = {}


@client.event
async def on_ready():

# initializing terminal text color
init(autoreset=True)

# Initialize the status of the bot in the presence
await client.change_presence(status=discord.Status.online, activity=discord.Activity(type=discord.ActivityType.playing, name="...loading"))
await client.change_presence(status=nextcord.Status.online, activity=nextcord.Activity(type=nextcord.ActivityType.playing, name="...loading"))


# Check if you have configured the discord server id
Expand All @@ -46,7 +46,7 @@ async def on_ready():
print(f"[{time.strftime('%d/%m/%y %H:%M:%S')}] ERROR: The owner_id set in the configuration file is invalid!")

global enabled_cogs
# Enable all cogs to the bot
# Search all cogs
for i in os.listdir('./cogs'):
if i.endswith('.py'):
client.load_extension(f'cogs.{i[:-3]}')
Expand All @@ -71,7 +71,7 @@ async def update_servers_status():
channel_message = server_id.get_channel(config['channel_status_id'])
if channel_message is not None:

txt = discord.Embed(title=config['message_title'], description=f"{config['message_description']}\n", colour=discord.Colour.orange())
txt = nextcord.Embed(title=config['message_title'], description=f"{config['message_description']}\n", colour=nextcord.Colour.orange())

with open('data.json') as data_file:
data = json.load(data_file)
Expand All @@ -81,10 +81,10 @@ async def update_servers_status():
try:

pinger_message = await channel_message.fetch_message(int(data['pinger_message_id']))
checking = discord.Embed(description=config["message_checking_embed"], colour=discord.Colour.orange())
checking = nextcord.Embed(description=config["message_checking_embed"], colour=nextcord.Colour.orange())
await pinger_message.edit(embed=checking)

except discord.errors.NotFound:
except nextcord.errors.NotFound:
return print(Style.NORMAL + Fore.RED + "[MCStatusBot] " + Fore.RESET + Fore.CYAN + f"The bot is not configured yet.. missing the command {config['bot_prefix']}createstatusmsg on the text channel")


Expand Down Expand Up @@ -122,7 +122,7 @@ async def update_servers_status():
print(f"[{time.strftime('%d/%m/%y %H:%M:%S')}] I could not find the indicated discord server.")
return 0
else:
await client.change_presence(status=discord.Status.idle, activity=discord.Activity(type=discord.ActivityType.playing, name="🟠 Maintenance"))
await client.change_presence(status=nextcord.Status.idle, activity=nextcord.Activity(type=nextcord.ActivityType.playing, name="🟠 Maintenance"))

async def update_presence_status():
servers = count_all_servers.values()
Expand All @@ -131,7 +131,7 @@ async def update_presence_status():
if value.get("count_on_presence", False):
status.append(int(value.get('online', 0)))

await client.change_presence(status=discord.Status.online, activity=discord.Activity(type=discord.ActivityType.playing, name=config["presence_name"].format(players=sum(status))))
await client.change_presence(status=nextcord.Status.online, activity=nextcord.Activity(type=nextcord.ActivityType.playing, name=config["presence_name"].format(players=sum(status))))
count_all_servers.clear()

async def send_console_status():
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
mcstatus
discord
nextcord
asyncio
apscheduler
colorama

0 comments on commit 756b406

Please sign in to comment.