conqp / mcipc

A Minecraft server inter-process communication library.
GNU General Public License v3.0
81 stars 11 forks source link

I'm having problems creating the code #43

Closed lipepeixoto closed 1 year ago

lipepeixoto commented 1 year ago

I can't understand what I did wrong. :(

import discord import mcipc.query import asyncio import time from discord.ext import commands, tasks from key import token

intents = discord.Intents.default() intents.members = True client = commands.Bot(command_prefix='!', intents=intents) TOKEN = token.get("TOKEN")

@client.event async def on_ready(): print(f'{client.user} está online!')

voice_channels = client.guilds[0].voice_channels
channel1 = next((vc for vc in voice_channels if vc.name == "Servidor Minecraft"), None)
channel2 = next((vc for vc in voice_channels if vc.name == "Jogadores Online"), None)

if not channel1:
    category = client.guilds[0].categories[0]
    channel1 = await category.create_voice_channel("Servidor Minecraft")

if not channel2:
    category = client.guilds[0].categories[0]
    channel2 = await category.create_voice_channel("Jogadores Online")

client.loop.create_task(update_status(channel1, channel2))

async def update_status(channel1, channel2): while True: try: host, port = "###.enxada.host", ##### with mcipc.query.Client(host, port) as client: status = client.full_stat()

        online_players = status['players']['online']
        max_players = status['players']['max']

        await channel1.edit(name=f"🟢 Servidor Online: {online_players}/{max_players}")
        await channel2.edit(name=f"🟢 {online_players}/{max_players} Jogadores Online")

    except Exception as e:
        # Em caso de erro, mostrar mensagem no console
        print(f"Erro ao atualizar status do servidor: {e}")

    # Esperar 10 minutos antes de atualizar novamente
    await asyncio.sleep(600)

@client.command() async def status(ctx): await ctx.send("Adicionado Status do servidor")

@client.command() async def ping(ctx): await ctx.send('Pong! {0}'.format(round(bot.latency, 1)))

client.run(TOKEN)

conqp commented 1 year ago

Me neither, since

  1. You did not tell what the code is supposed to be doing.
  2. The code is not formatted correctly.
  3. There is no error message presented.

After all, if there is no concrete error with mcipc, you're in the wrong place here. I do not offer support for arbitrary user code here.

PS: Also mcipc.query.client.Client has no method command().