Python discord.py I';我试图从我的服务器发出一个afk命令,每次我运行我的机器人时,它都会给出一个错误

Python discord.py I';我试图从我的服务器发出一个afk命令,每次我运行我的机器人时,它都会给出一个错误,python,cmd,command,python-asyncio,discord.py,Python,Cmd,Command,Python Asyncio,Discord.py,我正在尝试为我的服务器生成一个afk命令,每当我在cmd中运行它时,它都会出现以下错误: discord.ext.commands.errors.CommandInvokeError: Command raised an exception: AttributeError: 'Client' object has no attribute 'change_nickname' 我不知道为什么。任何对discord.py有相当了解的人能帮我解决这个问题吗? 以下是我目前

我正在尝试为我的服务器生成一个afk命令,每当我在cmd中运行它时,它都会出现以下错误:

    discord.ext.commands.errors.CommandInvokeError: Command raised an 
    exception: AttributeError: 'Client' object has no attribute 
    'change_nickname'
我不知道为什么。任何对discord.py有相当了解的人能帮我解决这个问题吗? 以下是我目前的代码:

import os
import discord
import asyncio
from discord.ext import commands

client = discord.Client()
bot_prefix="!"
bot = commands.Bot(command_prefix=bot_prefix)

@client.event
async def on_ready():
    print(f'{client.user} has connected to Discord!')

@client.event
async def on_member_join(member):
    await member.create_dm()
    await member.dm_channel.send(f"Hi {member.name}, welcome to the chiaravalle discord server, please read the rules")

@bot.command(pass_context=True)
async def yeet(ctx):
    await ctx.send("{0.author.mention} hit a yeet!".format(ctx.message))

@bot.command(pass_context=True)
async def ping(ctx):
    await ctx.send("Pong!")

@bot.command(pass_context=True)
async def afk(ctx, mins):
    await ctx.send("{0.author.mention} has gone afk for {1} minutes.".format(ctx, mins))
    await client.change_nickname(ctx.author.mention, "{0.author.mention} [AFK]".format(ctx))
    counter = 0
    while counter != mins:
        counter += 1
        await asyncio.sleep(60)
    if counter == mins:
        await ctx.send("{0.author.mention} is no longer AFK".format(ctx))


bot.run("my token")
client.run("my token")

你现在遇到的问题是,你必须以不同的方式更改某人的昵称。您可以使用编辑某人的信息

下面是您发送的代码的工作示例,它还将昵称重置为,而不使用[AFK]

@bot.command()
async def afk(ctx, mins):
    current_nick = ctx.author.nick
    await ctx.send(f"{ctx.author.mention} has gone afk for {mins} minutes.")
    await ctx.author.edit(nick=f"{ctx.author.name} [AFK]")

    counter = 0
    while counter <= int(mins):
        counter += 1
        await asyncio.sleep(60)

        if counter == int(mins):
            await ctx.author.edit(nick=current_nick)
            await ctx.send(f"{ctx.author.mention} is no longer AFK")
            break
@bot.command()
异步def afk(ctx,分钟):
当前_nick=ctx.author.nick
等待ctx.send(f“{ctx.author.antify}已离开afk{mins}分钟。”)
等待ctx.author.edit(nick=f“{ctx.author.name}[AFK]”)
计数器=0
柜台
如果原因仅仅是:

!afk afk

它说没有权限,没有帮助吗?你是想对自己这样做吗?我很确定它不起作用,因为你是服务器的所有者。但是,它可以在其他具有管理员权限的人身上工作。为什么它不适用于所有者,也不适用于其他任何人,所以serverowner就像一个不可接触的管理员,即使您的服务器上没有任何角色,serverowner也将具有管理员权限。关于其他人,您的机器人权限可能未正确设置,这在我自己的服务器上运行。尝试将机器人角色一直拖到角色列表的顶部。
@bot.command()
async def afk(ctx, reason=None):
    current_nick = ctx.author.nick
    await ctx.send(f"{ctx.author.mention} is afk: {reason} ")
    await ctx.author.edit(nick=f"[AFK] {ctx.author.name}")

    counter = 0
    while counter <= int(mins):
        counter += 1
        await asyncio.sleep(60)

        if counter == int(mins):
            await ctx.author.edit(nick=current_nick)
            await ctx.send(f"{ctx.author.mention} is no longer AFK")
            break
@2vw has gone afk for AFK minutes