7
7
8
8
9
9
@bot .command ()
10
- async def start (ctx : ApplicationContext , encoding : Option (str , choices = ["mp3" , "wav" , "pcm" , "ogg" , "mka" , "mkv" , "mp4" , "m4a" ,])):
10
+ async def start (ctx : ApplicationContext ,
11
+ encoding : Option (str , choices = ["mp3" , "wav" , "pcm" , "ogg" , "mka" , "mkv" , "mp4" , "m4a" , ])):
11
12
"""
12
13
Record your voice!
13
14
"""
@@ -36,26 +37,28 @@ async def start(ctx: ApplicationContext, encoding: Option(str, choices=["mp3", "
36
37
sink = discord .sinks .MP4Sink ()
37
38
elif encoding == "m4a" :
38
39
sink = discord .sinks .M4ASink ()
40
+ else :
41
+ return await ctx .respond ("Invalid encoding." )
39
42
40
43
vc .start_recording (
41
44
sink ,
42
45
finished_callback ,
43
46
ctx .channel ,
44
47
)
45
-
48
+
46
49
await ctx .respond ("The recording has started!" )
47
50
48
51
49
52
async def finished_callback (sink , channel : discord .TextChannel , * args ):
50
-
51
53
recorded_users = [
52
- f" <@{ user_id } > ( { os . path . split ( audio . file )[ 1 ] } ) "
54
+ f"<@{ user_id } >"
53
55
for user_id , audio in sink .audio_data .items ()
54
56
]
55
57
await sink .vc .disconnect ()
56
- files = sink .get_all_audio ()
58
+ files = [ discord . File ( audio . file , f" { user_id } . { sink .encoding } " ) for user_id , audio in sink . audio_data . items ()]
57
59
await channel .send (f"Finished! Recorded audio for { ', ' .join (recorded_users )} ." , files = files )
58
60
61
+
59
62
@bot .command ()
60
63
async def stop (ctx ):
61
64
"""
@@ -70,4 +73,4 @@ async def stop(ctx):
70
73
await ctx .respond ("Not recording in this guild." )
71
74
72
75
73
- bot .run ("TOKEN" )
76
+ bot .run ("TOKEN" )
0 commit comments