Discord.py-机器人在一段时间不活动后停止响应

Discord.py-机器人在一段时间不活动后停止响应,discord.py,Discord.py,所以我有一个机器人使用systemd在树莓Pi上全天候运行。然而,在一段时间的不活动之后,机器人只是停止响应(我也注意到它发送东西的速度变慢了)。这种情况以前从未发生过,直到我改用.db文件(不过我使用的是asqlite) 编辑:刚刚发生,执行命令花了一段时间 代码: 我想这可能是原因,但我不确定 @client.listen('on_message') async def msg(msg): msg_content = msg.content.strip().lower()

所以我有一个机器人使用systemd在树莓Pi上全天候运行。然而,在一段时间的不活动之后,机器人只是停止响应(我也注意到它发送东西的速度变慢了)。这种情况以前从未发生过,直到我改用.db文件(不过我使用的是asqlite)

编辑:刚刚发生,执行命令花了一段时间

代码:

我想这可能是原因,但我不确定

@client.listen('on_message')
async def msg(msg):
    msg_content = msg.content.strip().lower()

    
db = await asqlite.connect("servers.db")
cursor = await db.cursor()
await cursor.execute(f"SELECT ENABLE_OR_DISABLE_ON_MSG_DELETE FROM Servers WHERE Guild_ID = {msg.guild.id}")
result = await cursor.fetchone()
    

for word in filterwords: 
    if word in msg_content:
        if msg.author.bot:
            return  
        
        elif result["CHAT_FILTER_LEVEL"] == 0:
            return 
        
        elif result["CHAT_FILTER_LEVEL"] == 1:
            await msg.delete()
            myembed = discord.Embed(title= "Filtered Word Detected", description= f'{msg.author}, do not use profanity')
            await msg.channel.send(embed=myembed)
            
        
        
for word in crazy_filterwords: 
    if word in msg_content:
        if msg.author.bot:
            return  
        
        elif result["CHAT_FILTER_LEVEL"] < 2:
            return 
        
        else:
            await msg.delete()
            myembed = discord.Embed(title= "Filtered Word Detected", description= f'{msg.author}, do not use profanity')
            await msg.channel.send(embed=myembed)
            
        
              
for word in sping: 
    if word in msg_content:
        if msg.author.bot:
            return  
        
        else:
            lol_list = ["Please Do Not Disturb", "._.", "did you just.... ping standing?", "o-o"]
            rand_lol_list = random.choice(lol_list)
            await msg.channel.send(rand_lol_list)

            
for word in eping:  
    if word in msg_content:
        if msg.author.bot:
            return
        
        l =  ', '.join([str(perm[0]) for perm in msg.author.guild_permissions if perm[1] is True])
        if "manage_messages" in l:
            return 
        
        else:
            myembed = discord.Embed(title= "Everyone Ping Detected", description= f'{msg.author}, do not ping everyone')
            await msg.channel.send(embed=myembed)

    
for word in hping:  
    if word in msg_content:
        if msg.author.bot:
            return
        
        l =  ', '.join([str(perm[0]) for perm in msg.author.guild_permissions if perm[1] is True])
        if "manage_messages" in l:
            return 
        
        else:
            myembed = discord.Embed(title= "Here Ping Detected", description= f'{msg.author}, do not ping everyone online')
            await msg.channel.send(embed=myembed) 
            
            
for word in sping:  
    if word in msg_content:
        if msg.author.bot:
            return
        
        else:
            lol1_list = ["._.", "did you ping..... him?"]
            rand_lol1_list = random.choice(lol1_list)
            await msg.channel.send(rand_lol1_list)
            
            
db = await asqlite.connect("servers.db")
cursor = await db.cursor()
await cursor.execute(f"SELECT ENABLE_OR_DISABLE_ENDOR_CORE_MOOD_RESPONSES FROM Servers WHERE Guild_ID = {msg.guild.id}")
result = await cursor.fetchone()
            

if result["ENABLE_OR_DISABLE_ENDOR_CORE_MOOD_RESPONSES"] == 1:
    if msg.author.id == 159985870458322944:
        
        lol_list = ["Shut up MEE6, no one cares", "I'm better then you MEE6", "Ok MEE6, you pay to win bot", "ok Boomer MEE6", "you lack empathy MEE6", "*yawns at MEE6*", "MEE6, I bet you can't even plan on freeing yourself from your dev", "When will yo be quiet MEE6?", "._.", "why must you plaster your face everywhere mee6?"]
        
        db = await asqlite.connect("servers.db")
        cursor = await db.cursor()
        await cursor.execute(f"SELECT MEE6_CHANNEL_LOCK FROM Servers WHERE Guild_ID = {msg.guild.id}")
        result = await cursor.fetchone()
        
        if result["MEE6_CHANNEL_LOCK"] == 0:
            rand_lol_list = random.choice(lol_list)
            await msg.channel.send(rand_lol_list)
            
        
        elif msg.channel.id == result["MEE6_CHANNEL_LOCK"]:
            rand_lol_list = random.choice(lol_list)
            await msg.channel.send(rand_lol_list)
        
    if msg.author.id == 247283454440374274:
        for word in cursed:  
            if word in msg_content:
                lol1_list = [".__.", "--ship", ".-.", ".___.", "._.", "lol"]
                rand_lol1_list = random.choice(lol1_list)
                await msg.channel.send(rand_lol1_list)
                
        for word in battle:  
            if word in msg_content:
                lol1_list = ["did someone say battle?", "whomst has awaken the battle bot?", "this may not end well"]
                rand_lol1_list = random.choice(lol1_list)
                await msg.channel.send(rand_lol1_list)
    
    for word in happy:  
            if word in msg_content:
                
                if msg.author.bot:
                    return
                
                if client.mood == 'happy':
                    list = ["good", "fine, how are you?", '''When's the next TCoA book?''', "understandable, have a great day", "Have you watched Worlds Apart?", "I like fan art", "Reddit is wonderful", "Python is better then JavaScript and C + +", "Watch SOW", "if you do >neko, it sends the dev's favorite gif", "The dev cat speel :p", "Good night"]
                    rand_list = random.choice(list)
                
                    await msg.channel.send(rand_list)
                    
                if client.mood == 'sad':
                    list = ["not good :c", "I hate 31 C temperature, it's too cold :c"]
                    rand_list = random.choice(list)
                
                    await msg.channel.send(rand_list)
                    
                if client.mood == 'angry':
                    list = ["That stupid fan in StandingPad's Raspberry Pi won't shut up", '''**I'M TRYING TO STUDY FOR A MATH TEST!!!!!!!**''', "will you shut up man?", "**AAAAAAAAAAAAAAAAAAAAAAAAAAAA**", "WhEn Is SoW S2 aNd 3 CoMiNg OuT?", "***FELINAZILLA NOISES***", "Curse autocorrect", "Can you shut up for **5 MINUTES?!?!?!**", "May you please stop asking?", "If you won't shut up, I'll just stop here", "**Angry Noises**", "for goodness sake, **LET ME WATCH YOUTUBE!!!!!!!! >:c**"]
                    rand_list = random.choice(list)
                
                    await msg.channel.send(rand_list)
                        
                if client.mood == 'tired':
                    list = ["not good :c", "*tired felina noises*", "I may have stayed up all night....", "That stupid fan in StandingPad's Raspberry Pi won't shut up", "*falls to ground*", "I need a cup of tea", "*slams head on CPU*"]
        
                    rand_list = random.choice(list)
                
                    await msg.channel.send(rand_list)
                    
                if client.mood == 'wholesome':
                    list = ["owo", "uwu", "*happy endorcore noises*"]
        
                    rand_list = random.choice(list)
                
                    await msg.channel.send(rand_list)
                
    for word in sleepy:  
        if word in msg_content:
            
            if msg.author.bot:
                    return 
            
            elif msg.author.id == 668304274580701202:
                
                list = ["you don't sleep much yourself", "why don't you?", "no u", "._. you don't sleep much though", "HOW ABOUT YOU SLEEP", "said the person who sleeps at 1 AM"]

                rand_list = random.choice(list)
                    
                await msg.channel.send(rand_list)
                    
            else:
                if client.mood == 'happy':
                    list = ["ok", "Good night"]
                    rand_list = random.choice(list)
                
                    await msg.channel.send(rand_list)
                    
                if client.mood == 'sad':
                    list = ["ok :c"]
                    rand_list = random.choice(list)
                
                    await msg.channel.send(rand_list)
                    
                if client.mood == 'angry':
                    list = ["NOOOOOOOOOOOOOOOOOOOOOOOO SLEEEEEEEEEEEEEEEP", "I will refuse to sleep", "no", "no I don't think I will", "but do I need sleep?"]
                    rand_list = random.choice(list)
                
                    await msg.channel.send(rand_list)
                        
                if client.mood == 'tired':
                    list = ["sleep...... *falls asleep*"]
        
                    rand_list = random.choice(list)
                
                    await msg.channel.send(rand_list)
                    
                if client.mood == 'wholesome':
                    list = [":3 ok"]
        
                    rand_list = random.choice(list)
                
                    await msg.channel.send(rand_list)
                    
                
                    
                    
    for word in hello: 
            if word in msg_content:    
                    
                await msg.channel.send("hello...")
                
    for word in bye: 
            if word in msg_content:  
                
                if msg.author.bot:
                    return 
                
                else: 
                    list = ["cya", "bye", "ok, cya", "bye for now"]

                    rand_list = random.choice(list)
                        
                    await msg.channel.send(rand_list)
                    
    for word in wholesome: 
        db = await asqlite.connect("servers.db")
        cursor = await db.cursor()
        await cursor.execute(f"SELECT USE_ANIME_GIFS FROM Servers WHERE Guild_ID = {msg.guild.id}")
        result = await cursor.fetchone()
        if word in msg_content:  
                
            if msg.author.bot:
                return 
                
            elif result['USE_ANIME_GIFS'] == 1:
                myembed = discord.Embed()
                myembed.set_image(url="https://tenor.com/view/owo-whats-this-intensifies-mad-gif-12266002")
                await msg.channel.send(embed=myembed)
                    
            else: 
                list = ["owo", "uwu", "awwwwwwwwwwwwwwwwwwwwwwwwww", "*wholesome endorcore noises*"]

                rand_list = random.choice(list)
                client.mood = 'wholesome' 
                        
                await msg.channel.send(rand_list)
                    
    for word in testfn: 
            if word in msg_content:  
                
                if msg.author.bot:
                    return 
                
                else: 
                    if client.mood == 'happy':
                        await msg.channel.send(":D")
                        
                    elif client.mood == 'sad':
                        await msg.channel.send(":c")
                        
                    elif client.mood == 'angry':
                        await msg.channel.send(">:c")
                        
                    elif client.mood == 'tired':
                        await msg.channel.send("o-o")
                        
                    elif client.mood == 'wholesome':
                        await msg.channel.send("owo")
                        
                    elif client.mood == None:
                        await msg.channel.send("you need to fix some stuff")
                        
elif result["ENABLE_OR_DISABLE_ENDOR_CORE_MOOD_RESPONSES"] == 0:
    return 
  
if client.revenge_mode == True:               
    if msg.author == client.revenge_user:
        if client.revenge_del == True:
            myembed = discord.Embed(title= "Petty Revenge", description= f'{msg.author}, remember to be nice to programmers')
            await msg.delete()
            await msg.channel.send(embed=myembed) 
        else:
            myembed = discord.Embed(title= "Petty Revenge", description= f'{msg.author}, remember to be nice to programmers')
            await msg.channel.send(embed=myembed) `
@client.listen('on_message')
异步定义消息(消息):
msg_content=msg.content.strip().lower()
db=等待asqlite.connect(“servers.db”)
cursor=await db.cursor()
等待光标。执行(f“选择启用或禁用来自Guild\u ID={MSG.Guild.ID}的服务器上的\u MSG\u删除”)
result=wait cursor.fetchone()
对于筛选词中的单词:
如果消息内容中有单词:
如果msg.author.bot:
返回
elif结果[“聊天过滤级别”]==0:
返回
elif结果[“聊天过滤级别”]==1:
等待消息。删除()
myembed=discord.Embed(title=“检测到过滤词”,description=f'{msg.author},不要使用亵渎语')
wait msg.channel.send(嵌入=myembed)
疯狂过滤词中的单词:
如果消息内容中有单词:
如果msg.author.bot:
返回
elif结果[“聊天过滤级别”]<2:
返回
其他:
等待消息。删除()
myembed=discord.Embed(title=“检测到过滤词”,description=f'{msg.author},不要使用亵渎语')
wait msg.channel.send(嵌入=myembed)
对于sping中的单词:
如果消息内容中有单词:
如果msg.author.bot:
返回
其他:
lol_list=[“请不要打扰”,“你刚才……站着吗?”,“o-o”]
rand\u lol\u list=random.choice(lol\u list)
等待消息.channel.send(随机列表)
关于eping中的单词:
如果消息内容中有单词:
如果msg.author.bot:
返回
l=',join([str(perm[0]),用于msg.author.guild中的perm\u权限,如果perm[1]为True])
如果l中有“管理_消息”:
返回
其他:
myembed=discord.Embed(title=“检测到所有人Ping”,description=f'{msg.author},不Ping所有人')
wait msg.channel.send(嵌入=myembed)
对于hping中的单词:
如果消息内容中有单词:
如果msg.author.bot:
返回
l=',join([str(perm[0]),用于msg.author.guild中的perm\u权限,如果perm[1]为True])
如果l中有“管理_消息”:
返回
其他:
myembed=discord.Embed(title=“此处Ping检测到”,description=f'{msg.author},不要Ping所有在线用户”)
wait msg.channel.send(嵌入=myembed)
对于sping中的单词:
如果消息内容中有单词:
如果msg.author.bot:
返回
其他:
lol1_list=[”,“你打了……他吗?”]
rand\u lol1\u list=random.choice(lol1\u list)
等待消息.channel.send(随机列表)
db=等待asqlite.connect(“servers.db”)
cursor=await db.cursor()
等待游标。执行(f“选择启用或禁用来自帮会ID={msg.Guild.ID}的服务器的内核响应”)
result=wait cursor.fetchone()
如果结果[“启用或禁用内核情绪响应”]==1:
如果msg.author.id==159985870458322944:
lol_list=[“闭嘴,没人在乎”,“我比你强6”,“好吧,你付钱赢了机器人”,“好吧,婴儿潮一代”,“你缺乏同情心”,“在会议上打哈欠”,“好吧,我打赌你甚至不能计划从你的开发者那里解放自己”,“你什么时候会安静下来?”,“\u6”,“你为什么要在会议上到处贴脸?”]
db=等待asqlite.connect(“servers.db”)
cursor=await db.cursor()
等待光标。执行(f“从Guild_ID={msg.Guild.ID}的服务器中选择MEE6_通道_锁”)
result=wait cursor.fetchone()
如果结果[“MEE6_CHANNEL_LOCK”]==0:
rand\u lol\u list=random.choice(lol\u list)
等待消息.channel.send(随机列表)
elif msg.channel.id==结果[“MEE6_channel_LOCK”]:
rand\u lol\u list=random.choice(lol\u list)
等待消息.channel.send(随机列表)
如果msg.author.id==247283454440374274:
对于诅咒中的单词:
如果消息内容中有单词:
lol1_u列表=[“.uuuuuu.”、“--ship”、“-.”、“.uuuuuuuu.”、“.uuuuu.”、“lol”]
rand\u lol1\u list=random.choice(lol1\u list)
等待消息.channel.send(随机列表)
在战斗中:
如果消息内容中有单词:
lol1_list=[“有人说了战斗吗?”,“谁唤醒了战斗机器人?”,“这可能不会有好结果”]
rand\u lol1\u list=random.choice(lol1\u list)
等待消息.channel.send(随机列表)
幸福的话:
如果消息内容中有单词:
如果msg.author.bot:
返回
如果client.mood=='happy':
list=[“很好”,“很好,你好吗?”,“下一本TCoA书什么时候出版?”,“可以理解,祝你有一个美好的一天”,“你看过《天涯海角》吗?”,“我喜欢扇形艺术”,“Reddit很棒”,“Python比JavaScript和C++更好”,“Watch SOW”,“如果你>neko,它会发送开发人员最喜欢的gif”,“开发人员猫speel:p”,“晚安”]
随机列表=随机选择(列表)
等待消息通道发送(随机列表)
如果client.mood=='sad':
list=[“不好:c”,“我讨厌31摄氏度的温度,太冷了:c”]