[英]Python discord bot “Command 'ban' is not found” error
伙計們,我正在嘗試制作 discord 機器人,當我嘗試禁止成員時,我收到錯誤“discord.ext.commands.errors.CommandNotFound:找不到命令“ban””
這是我的代碼:
import discord
from discord.ext import commands
client = discord.Client
client = commands.Bot(command_prefix = '-')
@client.event
async def on_ready():
print("Logged in as {0.user} ".format(client))
@client.event
async def on_member_join(member):
print(f'{member} joined a server')
@client.event
async def on_member_remove(member):
print(f'{member} left a server')
@commands.command()
@commands.has_permissions(ban_members=True)
async def ban(self, ctx, member: discord.Member, *, reason=None):
await member.ban(reason=reason)
await ctx.send(f'User {member} has been kick')
client.run('TOKEN')
如果有人可以幫助我,我會非常高興。 謝謝
您必須將名稱傳遞給@commands.command()
裝飾器。
@commands.command(name='ban', description='Bans a user')
@commands.has_permissions(ban_members=True)
async def ban(self, ctx, member: discord.Member, *, reason=None):
await member.ban(reason=reason)
await ctx.send(f'User {member} has been kick')
並且不需要第一個客戶端變量,因為您在它之后的行聲明另一個客戶端變量並且它沒有做太多。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.