Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I'm having problems creating the code #43

Closed
lipepeixoto opened this issue Mar 15, 2023 · 1 comment
Closed

I'm having problems creating the code #43

lipepeixoto opened this issue Mar 15, 2023 · 1 comment

Comments

@lipepeixoto
Copy link

lipepeixoto commented Mar 15, 2023

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
Copy link
Owner

conqp commented Mar 17, 2023

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().

@conqp conqp closed this as completed Mar 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants