Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/296.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 未关闭的客户端会话。有解决办法吗?_Python_Python 3.x_Discord_Python Asyncio_Discord.py - Fatal编程技术网

Python 未关闭的客户端会话。有解决办法吗?

Python 未关闭的客户端会话。有解决办法吗?,python,python-3.x,discord,python-asyncio,discord.py,Python,Python 3.x,Discord,Python Asyncio,Discord.py,我正在使用Discord模块,制作一个Discord机器人。我在这方面做得很差,因为我不久前就开始编写代码了。嗯,我在设置机器人的前缀时遇到了一些问题:它说第8行有一个错误未关闭的客户端会话和名称错误:未定义名称“命令” 以下是错误: Traceback (most recent call last): File "SUBLIME TEXT PRUEBA.py", line 8, in <module> client = command.Bot(command_prefix = '!

我正在使用Discord模块,制作一个Discord机器人。我在这方面做得很差,因为我不久前就开始编写代码了。嗯,我在设置机器人的前缀时遇到了一些问题:它说第8行有一个错误<代码>未关闭的客户端会话和
名称错误:未定义名称“命令”

以下是错误:

Traceback (most recent call last):
File "SUBLIME TEXT PRUEBA.py", line 8, in <module>
client = command.Bot(command_prefix = '!')
NameError: name 'command' is not defined
Unclosed client session
client_session: <aiohttp.client.ClientSession object at 0x0000017638A4F9E8>

如评论中所述:

  • 您需要使用
    命令
    而不是
    命令
  • 您的
    discord.Client()
    会话需要关闭,可能需要使用类似
    close()

您可以编写命令,但可以导入命令(复数)。是吗?我想在你的程序之前,你必须在discord.Client()对象上调用类似close()的东西ends@lhk哦,好吧。。我要试试看。。这是个愚蠢的错误,如果这是解决办法的话hehe@Ihk是的,非常确定这就是问题所在。@lhk是的,它工作得很好。谢谢!
import discord
from discord.ext.commands import Bot
from discord.ext import commands
import asyncio


Client = discord.Client()
client = command.Bot(command_prefix = '!')


@client.event
async def on_ready():
    print('bot is redey')

@client.event
async def on_message(message):
    if message.content == 'keke':
        await client.send_message(message.channel, 'KEKEKEKEKK')