Python 未关闭的客户端会话。有解决办法吗?
我正在使用Discord模块,制作一个Discord机器人。我在这方面做得很差,因为我不久前就开始编写代码了。嗯,我在设置机器人的前缀时遇到了一些问题:它说第8行有一个错误<代码>未关闭的客户端会话和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 = '!
名称错误:未定义名称“命令”
以下是错误:
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()
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')