【发布时间】:2021-09-05 03:25:55
【问题描述】:
我今天正在重新排列命令以使整个代码看起来更好,可能我做错了什么并且代码停止工作,控制台中没有显示错误,没有关于 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)
其余部分我没动过,所以肯定不错
【问题讨论】:
-
我真的真的很怀疑你会得到任何帮助,发布你的整个项目并等待有人为你调试它不是这个网站的目的。看看how to ask
-
始终维护您的代码的最后一个工作版本,以便您至少可以回滚任何更改。此外,说某事“不起作用”也不是很有帮助。明确指出预期的行为是什么以及当前正在发生什么。
标签: python discord discord.py