繁体   English   中英

回溯(最近一次调用最后一次):文件“main.py”,第 11 行,在<module>

[英]Traceback (most recent call last): File "main.py", line 11, in <module>

有这个“回溯(最近一次调用):文件“main.py”,第 11 行,@client.command() AttributeError: 'Client' object has no attribute 'command'" 错误来了是不是我做错了什么在代码中?

import os
import discord
from discord.ext import commands
from discord.ext.commands import Bot
from discord.ext.commands import has_permissions, MissingPermissions, is_owner
import json

client = discord.Client(command_prefix = ".")
status=discord.Status.idle

@client.command()
async def ban(ctx, member: discord.Member, reason=None):
    await member.ban(reason=reason)
    await ctx.send("member is banned")


@client.event
async def on_ready():
 print('we have logged in as {0.user}'.format(client))


my_secret = os.environ['Token']

client.run(my_secret)



更改client = discord.Client(command_prefix = ".")

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

# You have to write 
# client = commands.Bot(command_prefix = '!')
# then you only write  client.command() in line (11)
# And you have to also import from discord.ext import commands in line 2

import discord
from discord.ext import commands
import os

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

@client.event
async def on_ready():
  print("Bot is Online")

@client.command()
async def ping(ctx):
  await ctx.send("Pong")

client.run('WRITE YOUR TOKEN HERE')

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM