Discord Bot 与 Pyton Minecraft 服务器状态

问题描述 投票:0回答:0

我尝试制作一个不和谐的机器人来使我的世界服务器在线,但启动机器人后,值没有改变。

import discord
from discord.ext import commands
from discord import Interaction

import minestat
import time


def player_count():
    i = 0

    while (i < 1):
        ms = minestat.MineStat('serverip', serverport)
        print('Minecraft server status of %s on port %d:' % (ms.address, ms.port))
        if ms.online:
            server_status = ('Sunucu Aktif! version %s  %s out of %s players.' % (ms.version, ms.current_players, ms.max_players))
            return server_status  # Return the server status instead of assigning to global variable

client = commands.Bot(command_prefix=".", intents=discord.Intents.all())


@client.event
async def on_ready():
    server_status = player_count()  # Call the player_count function to get the status
    await client.change_presence(activity=discord.activity.Game(name=server_status), status=discord.Status.idle)
    print(f"{client.user.name} is logged in")

client.run(“bot_token”)

尝试过,但我有同样的问题:

import discord
from discord.ext import commands
from discord import Interaction
import minestat
import time


def player_count():
    ms = minestat.MineStat('serverip', serverport)
    server_status = ('Sunucu Aktif! version %s  %s out of %s players.' % (ms.version, ms.current_players, ms.max_players))
    return server_status  # Return the server status instead of assigning to global variable

client = commands.Bot(command_prefix=".", intents=discord.Intents.all())


@client.event
async def on_ready():
    server_status = player_count()  # Call the player_count function to get the status
    await client.change_presence(activity=discord.activity.Game(name=server_status), status=discord.Status.idle)
    print(f"{client.user.name} is logged in")
    while True:
        time.sleep(60)
        server_status = player_count()
        await client.change_presence(activity=discord.activity.Game(name=server_status), status=discord.Status.idle)


client.run("bot_token")

错误:

[2024-05-05 00:34:51] [INFO]discord.client:使用静态令牌登录 [2024-05-05 00:34:52] [INFO ]discord.gateway:分片 ID 没有连接到网关(会话 ID:c29fff29e2317467a3bfbca68c76aa83)。 RS的Main已登录 [2024-05-05 00:35:43] [警告]discord.gateway:分片 ID 无心跳阻塞超过 10 秒。 循环线程回溯(最近一次调用最后一次): 文件“C:\Users\playe\PycharmProjects\pythonProject1\main.py”,第 27 行,位于 client.run("MTIzNjQxMTI2ODk4NjgzMDg3OQ.Gvzhao.__aMFjviZKlS8AG09KDBI2bkslSeXMYH2FMA7s") 文件“C:\Users\playe\PycharmProjects\pythonProject1.venv\Lib\site-packages\discor

python discord.py minecraft
© www.soinside.com 2019 - 2024. All rights reserved.