我有一个正在尝试制作多语言的机器人。现在,当我尝试为我得到的机器人运行命令时
UnicodeDecodeError: 'ascii' codec can't decode byte 0xf0 in position 7: ordinal not in range(128)
我尝试删除 .po 文件中的 🏓 表情符号并将其转换回 .mo 然后它起作用了。所以似乎🏓是这一切的问题。
示例:我的德语 .po 文件:
msgid "PING_TITLE"
msgstr "**PING 🏓**"
msgid "PING_DESCRIPTION"
msgstr "Meine Latenz ist **{ping}ms**!"
我的命令:
import gettext
import io
import json
from datetime import datetime
import discord
from discord import app_commands
from discord.ext import commands
class Ping(commands.Cog):
def __init__(self, client: commands.Bot):
self.client = client
with open("data/languages.json", encoding="utf-8") as f:
guild_languages = json.load(f)
lang = guild_languages.get(str(interaction.guild.id), "en")
trans = gettext.translation(
domain="ping", localedir="locales", languages=[lang], fallback=True
)
embed = discord.Embed(
title=str(trans.gettext("PING_TITLE")),
description=str(trans.gettext("PING_DESCRIPTION").format(ping=ping)),
color=0x1365EA,
timestamp=datetime.now(),
)
embed.set_author(
name=f"{interaction.user}", icon_url=f"{interaction.user.avatar.url}"
)
await interaction.response.send_message(embed=embed)
async def setup(client):
await client.add_cog(Ping(client))
就像我说的,没有表情符号一切正常!但我希望表情符号成为命令的一部分。
温馨提示:我还有一个.mo文件