读取文件时出现语法错误-Discord.py Rewrite

时间:2020-11-11 01:18:06

标签: python discord.py

我正在尝试读取文本文件中的行,以便可以进行某种形式的全局阻击命令,但是语法方面却存在问题。

[2020-11-10 20:13:11,921 botfile ERROR] Exception when attempting to load extension fun
Traceback (most recent call last):
  File "C:\Users\arsto\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\discord\ext\commands\bot.py", line 607, in _load_from_module_spec
    spec.loader.exec_module(lib)
  File "<frozen importlib._bootstrap_external>", line 779, in exec_module
  File "<frozen importlib._bootstrap_external>", line 916, in get_code
  File "<frozen importlib._bootstrap_external>", line 846, in source_to_code
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "C:\Users\arsto\secret\cogs\fun.py", line 72
    embed.set_author(name=f"Message sent by <@{thesniped}>!"
    ^
SyntaxError: invalid syntax

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "C:\Users\arsto\secret\botfile.py", line 166, in <module>
    client.load_extension(f"cogs.{i[0:-3]}")
  File "C:\Users\arsto\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\discord\ext\commands\bot.py", line 664, in load_extension
    self._load_from_module_spec(spec, name)
  File "C:\Users\arsto\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\discord\ext\commands\bot.py", line 610, in _load_from_module_spec
    raise errors.ExtensionFailed(key, e) from e
discord.ext.commands.errors.ExtensionFailed: Extension 'cogs.fun' raised an error: SyntaxError: invalid syntax (fun.py, line 72)
   @commands.command()
    async def globalsnipe(self, ctx):
        globalsnipeservers = objectfile.globalsnipeservers
        if ctx.guild.id in globalsnipeservers:
            textfile = open("C:/users/arsto/secret/globalsnipe.txt", "r")
            thesniped = textfile.readline(1)
            channel = textfile.readline(2)
            server = textfile.readline(4)
            messagecontent = textfile.readline(3)
            embed = discord.Embed(title="Message Sniped!", color=0xE71D36
            embed.set_author(name=f"Message sent by <@{thesniped}>!"
            embed.add_field(name=f"Channel",value=f"{channel}", inline=True)
            embed.add_field(name=f"Server", value=f"{server}", inline=True)
            embed.add_field(name=f"Message", value=f"{messagecontent}", inline=False)
            await ctx.send(embed=embed)

如果有人可以帮助我,将不胜感激。 谢谢

1 个答案:

答案 0 :(得分:1)

您忘记了右括号

embed = discord.Embed(title="Message Sniped!", color=0xE71D36

应该是

embed = discord.Embed(title="Message Sniped!", color=0xE71D36)