我该怎么做才能让我的机器人再次工作?不和谐.py

时间:2021-06-21 12:48:30

标签: python discord discord.py

我今天重新排列命令以使整个代码看起来更好,可能我做错了什么,代码停止工作,控制台中没有显示错误,没有关于 bot 的信息开始工作。如果有人帮助,我将不胜感激。 :)

import datetime
import json
import discord
from discord.ext import commands, tasks
from itertools import cycle
from discord.ext.commands import command, cooldown, BucketType

def get_prefix(client, message):
    with open('prefixes.json', 'r') as f:
        prefixes = json.load(f)

    return prefixes[str(message.guild.id)]

client = commands.Bot(command_prefix = get_prefix) #prefix bota

client.remove_command('help') #usunięcie zbędnej komendy
status = cycle(['Serwer ?????? ?', 'IP: ????????.??? ?', 'Wersja ?.??.?+ ?', '.????? - FineCone']) #Status bota
time = datetime.datetime.utcnow() #ustawienie czasu
client.run("there is a token but i deleted it in notepad :)") #token
wersja = "0.1.1" #wersja bota



@client.event
async def on_ready():
    change_status.start()
    print('Status zaaktualizowany, Bonjour.') #Wiadomość Pokazuje się na konsoli gdy bot się załaduje

@tasks.loop(seconds=10)
async def change_status():
    await client.change_presence(activity=discord.Game(next(status)))

@client.event
async def on_guild_join(guild):
    with open('prefixes.json', 'r') as f:
        prefixes = json.load(f)

    prefixes[str(guild.id)] = '.'

    with open('prefixes.json', 'w') as f:
        json.dump(prefixes, f, indent=4)

@client.event
async def on_guild_remove(guild):
    with open('prefixes.json', 'r') as f:
        prefixes = json.load(f)

    prefixes.pop(str(guild.id))

    with open('prefixes.json', 'w') as f:
        json.dump(prefixes, f, indent=4)

剩下的我没动过,所以绝对不错

1 个答案:

答案 0 :(得分:1)

client.run("token") 放在文件的结尾,而不是顶部。它下面的所有内容将永远不会被执行。

time = datetime.datetime.utcnow() #ustawienie czasu
# !! this is not supposed to be up here !!
client.run("there is a token but i deleted it in notepad :)") # token | remove this
wersja = "0.1.1" #wersja bota

@client.event
...
# .. events & commands

# instead put it on the LAST line
client.run("there is a token but i deleted it in notepad :)") # token