async def 번역모드(ctx, number, tonumber):
def check(m):
return m.author == ctx.author and m.channel == ctx.channel
print("{} and {}".format(number, tonumber))
#if number > 3 or tonumber>3 or number < 1 or tonumber < 1 or number == tonumber:
# await ctx.send("There is a problem with the command. Please try again.")
# return
# 1 == kor, 2 == eng, 3 == jpn
await ctx.send("Please enter the sentence you want to translate.")
while True:
sentence = await client.wait_for("message", check=check)
print("translation {}".format(sentence.content))
if sentence.content == "stop":
await ctx.send("The translation mode has ended.")
break
if sentence.content is not None:
await ctx.send("I received a sentence.")
if number == 1 and tonumber == 2:
print("let's start translation")
result1 = translator.translate(sentence.content, dest='en')
print("{}".format(result1.text))
await ctx.send("{}".format(result1.text))
I'm making a translation bot on Discord. The number and tonumber is to choose a language. ex) 1 == kor, 2 == eng, 3 == jpn Receiving sentences was successful. So it's printed out that it was delivered well. But
if number == 1 and tonumber == 2:
print("let's start a translation")
result1 = translator.translate(sentence.content, dest='en')
print("{}".format(result1.text))
await ctx.send("{}".format(result1.text))
It doesn't go over here. I added a print("let's start a translation") to see if it's moving on. It's not being printed out
Just in case, I'll write down all the codes.
from asyncio.windows_events import NULL
from discord.ext import commands
import discord
import time
import difflib
import asyncio
import googletrans
translator = googletrans.Translator()
client = discord.Client()
token = "I'll cover it up."
intents = discord.Intents.default()
intents.members = True
client = commands.Bot(intents=intents, command_prefix='>')
@client.event
async def on_ready():
print(client.user.name)
print("Let's start driving the bot.")
game = discord.Game("Somethin' on your mind? ")
await client.change_presence(status=discord.Status.online, activity=game)
@client.event
async def on_voice_state_update(member, before, after):
if before.channel is None and after.channel is not None:
await member.guild.system_channel.send(
"{} has logged on to the voice channel.".format(member.name)
)
@client.command()
async def 정보(ctx):
members = [member.name for member in ctx.guild.members]
await ctx.send(
"{} server is {} server and Members {} and Total {} people.".format(
ctx.guild.name,
ctx.guild.region,
members,
ctx.guild.member_count
)
)
@client.command()
async def 어드민(ctx):
await ctx.send("This server admin is {}".format(
ctx.guild.owner
))
@client.command()
async def 안녕(ctx):
await ctx.send("You said {}, Nice to meet you {}!"
.format(ctx.message.content, ctx.author.name
))
@client.command(aliases=['translate', 'tl'])
async def 번역모드(ctx, number, tonumber):
def check(m):
return m.author == ctx.author and m.channel == ctx.channel
print("{} and {}".format(number, tonumber))
#if number > 3 or tonumber>3 or number < 1 or tonumber < 1 or number == tonumber:
# await ctx.send("There is a problem with the command. Please try again.")
# return
# 1 == kor, 2 == eng, 3 == jpn
await ctx.send("Please enter the sentence you want to translate.")
while True:
sentence = await client.wait_for("message", check=check)
print("translation {}".format(sentence.content))
if sentence.content == "stop":
await ctx.send("The translation mode has ended.")
break
if sentence.content is not None:
await ctx.send("I received a sentence.")
if number == 1 and tonumber == 2:
print("let's start translation")
result1 = translator.translate(sentence.content, dest='en')
print("{}".format(result1.text))
await ctx.send("{}".format(result1.text))
client.run(token)
I can't think of a way because I'm not good enough.
I used a translator, so I hope it's delivered well.
Oh, and...
import "googletrans" could not resolved
There's a warning, too.
Note the variable number and tonumber is not an integer, instead it is a string, so number
will be "1"
not 1
. Similarly tonumber
will be "2"
not 2
.
You can fix thix problem in two ways:
Before def check()
function just add number=int(number)
and tonumber=int(tonumber)
.
Change
async def 번역모드(ctx, number, tonumber):
to
async def 번역모드(ctx, number: int, tonumber: int):