【问题标题】:Unclosed client session. Any solution?未关闭的客户端会话。有什么解决办法吗?
【发布时间】:2019-04-17 05:30:31
【问题描述】:

我正在使用 Discord 模块来制作 Discord 机器人。我在这方面很糟糕,因为我不久前开始编码。好吧,我在为机器人设置前缀时遇到了一些问题:它说第 8 行有一个错误。unclosed client sessionNameError: 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')

【问题讨论】:

  • 您编写命令但您导入命令(复数)。是这样吗?
  • 我猜你必须在你的程序结束之前在你的 discord.Client() 对象上调用 close() 之类的东西
  • @lhk 哦,好吧.. 试试看.. 如果这是解决方案,那真是个愚蠢的错误,呵呵
  • @Ihk 是的,很确定这就是问题所在。
  • @lhk 是的,它运行良好。谢谢!

标签: python python-3.x discord python-asyncio discord.py


【解决方案1】:

如 cmets 中所述:

  • 您需要使用commands 而不是command
  • 您的discord.Client() 会话需要关闭,可能使用close() 之类的方法

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-27
    • 2018-05-08
    相关资源
    最近更新 更多