import disnake
import os
from disnake.ext import commands
import json
def get_server_prefix(bot, message):
with open("prefix.json", "r") as f:
prefix = json.load(f)
return prefix[str(message.guild.id)]
bot = commands.Bot(command_prefix=get_server_prefix, help_command=None, intents=disnake.Intents.all())
bot.remove_command('help')
@bot.event
async def on_ready():
print(f"Бот {bot.user} работает!")
activity = disnake.Activity(type=disnake.ActivityType.listening, name=F"...")
await bot.change_presence(status=disnake.Status.do_not_disturb, activity=activity)
@bot.event
async def on_guild_join(guild):
with open("prefix.json", "r") as f:
prefix = json.load(f)
prefix[str(guild.id)] = "bt."
with open("prefix.json", "w") as f:
json.dump(prefix, f, indent=4)
@bot.event
async def on_guild_remove(guild):
with open("prefix.json", "r") as f:
prefix = json.load(f)
prefix.pop(str(guild.id))
with open("prefix.json", "w") as f:
json.dump(prefix, f, indent=4)
@bot.command(administrator=True)
async def load(ctx, extension):
extension = extension.lower()
bot.load_extension(f'cogs.{extension}')
await ctx.send(f'{extension} загружен')
@bot.command(administrator=True)
async def unload(ctx, extension):
extension = extension.lower()
bot.unload_extension(f'cogs.{extension}')
await ctx.send(f'{extension} отгружен')
@bot.command(administrator=True)
async def reload(ctx, extension):
extension = extension.lower()
bot.unload_extension(f'cogs.{extension}')
bot.load_extension( f'cogs.{extension}' )
await ctx.send(f'**{extension}** **перезагружен**')
for fn in os.listdir('./cogs'):
if fn.endswith('.py'):
bot.load_extension(f"cogs.{fn[:-3]}")
TOKEN = "..."
bot.run(TOKEN)
Ignoring exception in on_guild_join
Traceback (most recent call last):
File "C:\bot\venv\lib\site-packages\disnake\client.py", line 705, in _run_event
await coro(*args, **kwargs)
File "c:\bot\bot.py", line 27, in on_guild_join
prefix = json.load(f)
File "C:\Users\fixik\AppData\Local\Programs\Python\Python39\lib\json\__init__.py", line 293, in load
return loads(fp.read(),
File "C:\Users\fixik\AppData\Local\Programs\Python\Python39\lib\json\__init__.py", line 346, in loads
return _default_decoder.decode(s)
File "C:\Users\fixik\AppData\Local\Programs\Python\Python39\lib\json\decoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "C:\Users\fixik\AppData\Local\Programs\Python\Python39\lib\json\decoder.py", line 355, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
Traceback (most recent call last):
File "C:\bot\venv\lib\site-packages\disnake\ext\commands\common_bot_base.py", line 453, in _load_from_module_spec
setup(self)
File "c:\bot\cogs\help.py", line 26, in setup
bot.add_cog(Help(bot))
File "C:\bot\venv\lib\site-packages\disnake\ext\commands\common_bot_base.py", line 341, in add_cog
cog = cog._inject(self) # type: ignore
File "C:\bot\venv\lib\site-packages\disnake\ext\commands\cog.py", line 818, in _inject
bot._schedule_delayed_command_sync()
File "C:\bot\venv\lib\site-packages\disnake\ext\commands\interaction_bot_base.py", line 916, in _schedule_delayed_command_sync
self.loop.create_task(self._delayed_command_sync(), name="disnake: delayed_command_sync")
File "C:\Users\fixik\AppData\Local\Programs\Python\Python39\lib\asyncio\base_events.py", line 436, in create_task
self._check_closed()
File "C:\Users\fixik\AppData\Local\Programs\Python\Python39\lib\asyncio\base_events.py", line 515, in _check_closed
raise RuntimeError('Event loop is closed')
RuntimeError: Event loop is closed