-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
47 lines (33 loc) · 1.14 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import discord
import os
import googletrans
import discord.ext
from discord.ext import commands, tasks
from discord.ext.commands import has_permissions, CheckFailure, check
#import statements
description = "Switch is a multilingual translation and moderation bot, built for the purpose of easing communication."
#Bot Setup
intents = discord.Intents().all()
bot = commands.Bot(
command_prefix="!",
case_insensitive=True, intents=intents
)
#Bot login
@bot.event
async def on_ready():
print('We have logged in as {0.user}'.format(bot))
@bot.command()
async def ping(ctx):
await ctx.send("pong!") #simple command so that when you type "!ping" the bot will respond with "pong!"
@bot.command(aliases = ['tr'])
async def translate(ctx, lang_to, *args):
"""
Translates the given text to the language `lang_to`.
The language translated from is automatically detected.
"""
lang_to = lang_to.lower()
text = ' '.join(args)
translator = googletrans.Translator()
text_translated = translator.translate(text, dest=lang_to).text
await ctx.reply(text_translated, mention_author=False)
bot.run(os.getenv('TOKEN'))