Skip to content

Commit 165ca76

Browse files
committed
added translation cmd
1 parent 0e3be0b commit 165ca76

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

cogs/misc.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import google.generativeai as genai
1919
import button_paginator as pg
20+
from googletrans import Translator
2021

2122
if TYPE_CHECKING:
2223
from ext.models import CodingBot
@@ -494,6 +495,24 @@ async def on_timeout():
494495
paginator.on_timeout = on_timeout
495496

496497
await paginator.start()
498+
499+
@commands.command(name = "translate")
500+
async def _translate(self, ctx: commands.Context, *, text: str = None):
501+
if not ctx.message.reference and not text: return await ctx.reply("Please reply a message or provide a text to translate!")
502+
503+
if text:
504+
trans = text
505+
message = ctx.message
506+
else:
507+
message = await ctx.channel.fetch_message(ctx.message.reference.message_id)
508+
trans = message.content
509+
510+
try:
511+
translated = Translator(service_urls=['translate.google.com','translate.google.co.kr']).translate(trans)
512+
except Exception as e:
513+
raise e
514+
515+
await message.reply(embed = discord.Embed().add_field(name = f"Original ({translated.src.upper()})", value = trans, inline = False).add_field(name = f"Translated ({translated.dest.upper()})", value = translated.text, inline = False), allowed_mentions=discord.AllowedMentions.none())
497516

498517

499518
async def setup(bot: CodingBot):

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ more_itertools==10.2.0
1111
button_paginator @ git+https://github.com/andrewthederp/Button_paginator
1212
google-generativeai==0.5.4
1313
jishaku==2.5.2
14+
googletrans==4.0.0rc1

0 commit comments

Comments
 (0)