A bot like this
The method of making a bot with Discord is omitted. Please read around here. Practical Discord Bot in Python (discordpy explanation)
#Installed discord.Load py
import discord
from googletrans import Translator
#Replace with your bot's access token
TOKEN = '[bot-token]'
#Generate the objects needed for the connection
client = discord.Client()
#Processing that operates at startup
@client.event
async def on_ready():
#When started, a login notification will be displayed in the terminal
print('You are now logged')
@client.event
async def on_reaction_add(reaction, user):
print("emoji-id")
print(reaction.emoji.id)
if reaction.count == 1:
#Japanese translation
if reaction.emoji.id == 687336060556017758:
translator = Translator()
trans_en = translator.translate(reaction.message.content, src='en', dest='ja')
await reaction.message.channel.send(trans_en.text)
#English translation
if reaction.emoji.id == 687336087408214062:
translator = Translator()
trans_en = translator.translate(reaction.message.content, src='ja', dest='en')
await reaction.message.channel.send(trans_en.text)
#Launching a bot and connecting to a Discord server
client.run(TOKEN)
[bot-token] is the token of each bot. For [emoji-id], set the ID of the emoji you want to react to (Integer).
All you have to do is throw the translation to Google Translate and return the result in a message. Regarding emoji.id, if it is *** registered emoji ***, the emoji ID is assigned, so after setting the emoji on the server, react and solidify the emoji ID spit out in print. Let's write in. In my case, I translated the Japanese flag into Japanese and the American flag into English.
Since src is the sentence before translation and dest is the sentence after translation, it can be translated into English or Japanese.
When completed, deploy it around heroku and run it, and it will translate 24 hours a day, convenient! By the way, I didn't know how to get the number of reactions, so if I react 2 times, it will be translated twice.
Please tell me how to do it.
if reaction.count == 1:
Thank you @rareshana!
Practical Discord Bot in Python (discordpy explanation) How to detect reaction with Discord.py & list of parameters [Python] Try converting (translating) Japanese data to English using googletrans