forked from chocoboyx/heroko_discordbot4569
-
Notifications
You must be signed in to change notification settings - Fork 0
/
discordbot.py
38 lines (32 loc) · 1 KB
/
discordbot.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
import discord
import googletrans
import os
from pprint import pprint
# 輸入自己Bot的TOKEN碼
TOKEN = os.environ['TOKEN']
SRCLanguage=os.environ['SRC']
DSTLanguage=os.environ['DST']
client = discord.Client()
# 起動時呼叫
@client.event
async def on_ready():
print('成功登入')
# 收到訊息時呼叫
@client.event
async def on_message(message):
# 送信者為Bot時無視
if message.author.bot:
return
if client.user in message.mentions: # @判定
translator = googletrans.Translator()
robotName = client.user.name
first, space, content = message.clean_content.partition('@'+robotName+' ')
if content == '':
content = first
if translator.detect(content).lang == DSTLanguage:
return
if translator.detect(content).lang == SRCLanguage or SRCLanguage == '':
remessage = translator.translate(content, dest='zh-tw').text
await message.reply(remessage)
# Bot起動
client.run(TOKEN)