首页 > 解决方案 > @commands.has permissions(administrator=true) 命令没有属性 has_permisions 错误

问题描述

我正在编写一个机器人,这里是整个代码:

print("Loading bot...")
import discord
import time
import asyncio
import datetime
import requests
from discord.ext import commands
from discord.ext import tasks
from discord.utils import get
from webserver import keep_alive   
import os
intents = discord.Intents.default()
intents.members = True
bot = commands.Bot(command_prefix="t.", intents=intents)
bot.remove_command('help')

[Other code]    
    
#Purge command    
@bot.command(pass_context=True)
@commands.has_permissions(administrator=True)
async def purge(ctx, limit: int):
        await ctx.channel.purge(limit=limit)
        await ctx.send("Messages purged ")
        await ctx.message.delete()        

keep_alive()
bot.run('TOKEN)

我的错误: 点击这里

是的,我在 python 3.8.5 上使用 replit 有什么问题?希望你能回答我的问题。我真的不知道该怎么办,discord.py 是一种很奇怪的编程语言:/ 谢谢 Evo

标签: pythondiscorddiscord.pycommandbots

解决方案


将其导入您的文件中,from discord.ext.commands import has_permissions, MissingPermissions这可能会对您有所帮助并使该行@has_permissions(administrator=True)


推荐阅读