From 783da9ac3211d3f33021c317a7279bf575ab1d74 Mon Sep 17 00:00:00 2001 From: imnotverygood <68748172+imnotverygood@users.noreply.github.com> Date: Fri, 24 Jul 2020 17:19:37 +0100 Subject: [PATCH] Add BytesIO seek to fix empty file error "ValueError: embedded null byte" error on the discord attachment due to the data being read from the end. --- tts/tts.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tts/tts.py b/tts/tts.py index 02f8b8e..0009fbf 100644 --- a/tts/tts.py +++ b/tts/tts.py @@ -24,10 +24,11 @@ class TTS(Cog): @commands.command(aliases=["t2s", "text2"]) async def tts(self, ctx: commands.Context, *, text: str): - """ + """ Send Text to speech messages as an mp3 """ mp3_fp = io.BytesIO() tts = gTTS(text, "en") tts.write_to_fp(mp3_fp) - await ctx.send(file=discord.File(mp3_fp.getvalue(), "text.mp3")) + mp3_fp.seek(0) + await ctx.send(file=File(mp3_fp, "text.mp3"))