TextIOWrapper用齿轮创建记录器时参数不正确

时间:2020-05-29 22:49:22

标签: python logging discord discord.py

我正在尝试建立一个自动记录系统,该系统放置所有已发送和已删除的消息,但偶尔会出现此错误:

Exception ignored in: <_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'>
OSError: [WinError 87] The parameter is incorrect

重新启动机器人很容易,但是由于这是一个自动化系统,一旦遇到此错误,它将完全关闭并陷入打印此错误的循环中

这是我的代码:

from discord.ext import commands


# https://youtu.be/BoVOzm1uhUA
class Logger(commands.Cog):
    def __init__(self, bot):
        self.bot = bot

    @commands.Cog.listener()
    async def on_message(self, c):
        if(c.guild):
            if c.guild.name == "Server Name":
                if c.author.bot == True:
                    try:
                        print(f"Bot: {c.author} said --- {c.clean_content} --- in #{c.channel.name}")
                    except OSError:
                        print('An error occurred')
                        pass
                else:
                    try:
                        print(f"User: {c.author} said --- {c.clean_content} --- in #{c.channel.name}")
                    except OSError:
                        print('An error occurred')
                        pass
            elif c.guild.name == "Server 2 Name":
                if c.author.bot == True:
                    try:
                        print(f"Bot: {c.author} said --- {c.clean_content} --- in #{c.channel.name}")
                    except OSError:
                        print('An error occurred')
                        pass

                else:
                    try:
                        print(f"User: {c.author} said --- {c.clean_content} --- in #{c.channel.name}")
                    except OSError:
                        print('An error occurred')
                        pass

    @commands.Cog.listener()
    async def on_message_delete(self, c):
        if(c.guild):
            if c.guild.name == "Server Name":
                if c.author.bot == True:
                    print(f"Bot: {c.author} deleted --- {c.clean_content} --- in #{c.channel.name}")
                    pass
                else:
                    print(f"User: {c.author} deleted --- {c.clean_content} --- in #{c.channel.name}")
                    pass
            elif c.guild.name == "Server 2 Name":
                if c.author.bot == True:
                    print(f"Bot: {c.author} deleted --- {c.clean_content} --- in #{c.channel.name}")
                    pass
                else:
                    print(f"User: {c.author} deleted --- {c.clean_content} --- in #{c.channel.name}")
                    pass

#print(f"{c.created_at} || Bot: {c.author} deleted --- {c.clean_content} --- in #{c.channel.name}");

def setup(bot):
    bot.add_cog(Logger(bot))

如您所见,我已经尝试修复此错误,但没有成功 任何帮助深表感谢。这个错误使我发疯

0 个答案:

没有答案