Python discord.py 1.5.0:name错误:name';客户';没有定义

Python discord.py 1.5.0:name错误:name';客户';没有定义,python,discord.py,discord.py-rewrite,Python,Discord.py,Discord.py Rewrite,我不熟悉discord.py,并遵循有关cogs的教程。我遵循了教程告诉我的所有内容,但在运行命令时出现了名称错误 代码如下: /bot.py import os import discord from discord.ext import commands client = commands.Bot(command_prefix = '/') @client.event async def on_ready(): await client.change_presence(statu

我不熟悉
discord.py
,并遵循有关cogs的教程。我遵循了教程告诉我的所有内容,但在运行命令时出现了名称错误

代码如下:

/bot.py

import os
import discord
from discord.ext import commands

client = commands.Bot(command_prefix = '/')

@client.event
async def on_ready():
    await client.change_presence(status=discord.Status.online, activity=discord.Game('Under Development'))
    print('Bot Online')

@client.command()
async def load(ctx, extension):
    client.load_extension(f'cogs.{extension}')

@client.command()
async def unload(ctx, extension):
    client.unload_extension(f'cogs.{extension}')

for filename in os.listdir('./cogs'):
    if filename.endswith('.py'):
        client.load_extension(f'cogs.{filename[:-3]}')

client.run(os.environ['TOKEN'])
import discord
from discord.ext import commands

class Commands(commands.Cog):
    def __init__(self, client):
        self.client = client

    @commands.command()
    async def ping(self, ctx):
        await ctx.send(f'Network Delay: **{round(client.latency * 1000)} ms**')

def setup(client):
    client.add_cog(Commands(client))
/cogs.commands.py

import os
import discord
from discord.ext import commands

client = commands.Bot(command_prefix = '/')

@client.event
async def on_ready():
    await client.change_presence(status=discord.Status.online, activity=discord.Game('Under Development'))
    print('Bot Online')

@client.command()
async def load(ctx, extension):
    client.load_extension(f'cogs.{extension}')

@client.command()
async def unload(ctx, extension):
    client.unload_extension(f'cogs.{extension}')

for filename in os.listdir('./cogs'):
    if filename.endswith('.py'):
        client.load_extension(f'cogs.{filename[:-3]}')

client.run(os.environ['TOKEN'])
import discord
from discord.ext import commands

class Commands(commands.Cog):
    def __init__(self, client):
        self.client = client

    @commands.command()
    async def ping(self, ctx):
        await ctx.send(f'Network Delay: **{round(client.latency * 1000)} ms**')

def setup(client):
    client.add_cog(Commands(client))
当我在discord消息框中键入
/ping
时,我得到了这个回溯

回溯(最近一次呼叫最后一次): 文件“C:\Users\bryan\source\repos\discord\u music\u bot\env\lib\site packages\discord\ext\commands\bot.py”,第903行,在invoke中 等待ctx.command.invoke(ctx) 文件“C:\Users\bryan\source\repos\discord\u music\u bot\env\lib\site packages\discord\ext\commands\core.py”,调用中第859行 等待注入(*ctx.args,**ctx.kwargs) 文件“C:\Users\bryan\source\repos\discord\u music\u bot\env\lib\site packages\discord\ext\commands\core.py”,第94行,已包装 从exc引发CommandInvokeError(exc) discord.ext.commands.errors.CommandInvokeError:命令引发异常:NameError:未定义名称“客户端”


多亏了@Brian,我终于纠正了错误。我写
client.latency
而不是
self.client.latency

async def ping(self, ctx):
        await ctx.send(f'Network Delay: **{round(self.client.latency * 1000)} ms**')

您希望
命令中的
客户端
是什么?ping
?你的意思是写
self.client
?好吧,因为我是discord.py新手,我不知道我在做什么,只是按照教程做。在终端上再次看到错误后,我想我知道了错误可能在哪里。