edditing code

This commit is contained in:
2022-08-22 21:50:15 +03:00
parent 89707a7e9a
commit 3e7a812fdc
5 changed files with 64 additions and 29 deletions

View File

@@ -2,6 +2,8 @@ from os import listdir
"""
Loads, unloads Cogs files
cog_list: return list of cog filenames
"""
@@ -13,13 +15,6 @@ def cog_list():
return cogs_list
async def cogs_dict():
cog_dict = {}
for _cog in cog_list():
cog_dict.update({f'{_cog}': f'{_cog}'})
return cog_dict
async def work_with_cogs(what_do, bot):
for _filename in cog_list():
if what_do == "load":

View File

@@ -1,5 +1,9 @@
import json
from os import walk
"""
Some prepare for commands
"""
async def list_files(fold: str = 'audio'):
@@ -54,13 +58,14 @@ async def write_json(guild: int, param_name: str, param: str or int):
json.dump(_json, f, indent=4)
async def determine_prefix(bot, msg):
def determine_prefix(bot, msg):
"""
Determite per-server bot prefix
:param bot: Disnake Bot object
:param msg: Disnake msg object
:return: prefix for server, default is $
"""
parameter = '$'
with open('prefix.json', 'r', encoding='utf-8') as fp: # Open the JSON
try:
from json import load
@@ -69,6 +74,7 @@ async def determine_prefix(bot, msg):
_json = {}
try:
parameter = _json[f"{msg.guild.id}"]["prefix"] # Read prefix from json if is setted up
except:
parameter = '$'
pass
return parameter

14
lib/Player.py Normal file
View File

@@ -0,0 +1,14 @@
from asyncio import sleep
from disnake import FFmpegPCMAudio
async def play_audio(audio, bot, vc):
if not bot.voice_clients:
await sleep(1)
vp = await vc.connect()
if not vp.is_playing():
vp.play(FFmpegPCMAudio(f'audio/{audio}'), after=None)
while vp.is_playing():
await sleep(0.5)
await sleep(1)
await vp.disconnect()