sqlite TypeError:command_prefix必须是纯字符串、字符串的可迭代对象或返回其中之一的可调用对象,而不是NoneType

owfi6suc  于 2023-02-19  发布在  SQLite
关注(0)|答案(1)|浏览(134)

虽然我的sql很弱,但我不认为问题是来自sql。同样的情况,它正确地工作了1次,但它停止工作了。我不知道,请帮助这个问题真的困扰着我。
错误:

Traceback (most recent call last):
  File "C:\Users\Mahdiyar\AppData\Local\Programs\Python\Python311\Lib\site-packages\discord\ext\commands\bot.py", line 1199, in get_prefix      
    ret = list(ret)  # type: ignore
          ^^^^^^^^^
TypeError: 'NoneType' object is not iterable

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\Mahdiyar\AppData\Local\Programs\Python\Python311\Lib\site-packages\discord\client.py", line 409, in _run_event
    await coro(*args, **kwargs)
  File "C:\Users\Mahdiyar\AppData\Local\Programs\Python\Python311\Lib\site-packages\discord\ext\commands\bot.py", line 1394, in on_message      
    await self.process_commands(message)
  File "C:\Users\Mahdiyar\AppData\Local\Programs\Python\Python311\Lib\site-packages\discord\ext\commands\bot.py", line 1389, in process_commands    ctx = await self.get_context(message)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Mahdiyar\AppData\Local\Programs\Python\Python311\Lib\site-packages\discord\ext\commands\bot.py", line 1288, in get_context     
    prefix = await self.get_prefix(origin)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Mahdiyar\AppData\Local\Programs\Python\Python311\Lib\site-packages\discord\ext\commands\bot.py", line 1206, in get_prefix      
    raise TypeError(
TypeError: command_prefix must be plain string, iterable of strings, or callable returning either of these, not NoneType

代码:

async def get_prefix(client, message):
    async with aiosqlite.connect("sqlite2023.db") as db:
        async with db.cursor() as cursor:
            await cursor.execute('SELECT prefix FROM prefix WHERE guild = ?' , (message.guild.id,))
            data = await cursor.fetchone()
            if data:
                return data
            else:
                try:
                    await cursor.execute('INSERT INTO prefix (prefix, guild) VALUES (? , ?)', ('!', message.guild.id,))
                    await cursor.execute('SELECT prefix FROM prefix WHERE guild = ?' , (message.guild.id,))
                    data = await cursor.fetchone()
                    if data:
                        cursor.execute('UPDATE prefix SET prefix = ? WHERE guild = ? ' , ('!',message.guild.id,))
                except Exception:
                    return '!'

@client.event #Client Statusa
async def on_ready():
    forever_print.start()
    asyncio.create_task(rich_persence())
    print("Client is online!")
    async with aiosqlite.connect("sqlite2023.db") as db:
        async with db.cursor() as cursor:
            await cursor.execute('CREATE TABLE IF NOT EXISTS prefix (prefix TEXT ,guild ID)')
        await db.commit()
htzpubme

htzpubme1#

该函数中的try块不返回任何内容,因此如果它不引发异常,则返回None而不是前缀。

相关问题