python - 未关闭的客户端会话。有什么解决办法吗?
问题描述
我正在使用 Discord 模块来制作 Discord 机器人。我在这方面很糟糕,因为我不久前开始编码。好吧,我在为机器人设置前缀时遇到了一些问题:它说第 8 行有一个错误..unclosed client session
还有NameError: name 'command' is not defined
。
这是错误:
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>
我也要把代码放在这里...
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')
解决方案
正如评论中所讨论的:
- 你需要使用
commands
而不是command
- 您的
discord.Client()
会话需要关闭,可能使用类似的方法close()
推荐阅读
- java - 场景:这个网页有一个包含 10 个网页链接的列表。单击每个 Web 链接并使用 selenium Java 在新窗口或选项卡中打开
- ruby-on-rails - 是否有针对我的情况使用 ActiveRecord#Pluck 的有效方法?
- .net-core - .net Core - 添加带有 JWT MVC 的 API 后,登录不再有效
- javascript - moment.js - 从星期日减去 1 天未按预期工作
- google-apps-script - GSuite Admin SDK > 目录 API:如何将值添加到用户的自定义架构?
- r - 在R中按一个列名合并数据集时如何删除重复的列名?
- if-statement - Excel formula has too many arguments
- r - 加权中位数 by_group()
- etl - SAP BODS - 从表比较中获取 PK 违规
- asp.net-core - 在 asp.net core 中加密 appsettings 和其他配置