简体   繁体   中英

does anyone know how to fix this discord.py error

I keep getting this error. Everything is imported right and everything is installed. The code was working in atom and then all of a sudden I get this error. Everything works in pycharm. Same error in vscode.

File "c:\Python\Python Tutorial\Discord Bot\Discord_Bot.py", line 5, in client = commands.Bot(command_prefix = ",") AttributeError: module 'discord.ext.commands' has no attribute 'Bot'

    import discord
from discord.ext import commands
import random

client = commands.Bot(command_prefix = ",")

def bot():
    print("hey im here")

@client.event
async def on_ready():
    bot()

# Ping Command
@client.command(aliases=["p"])
async def ping(ctx):
    await ctx.send("pong")

#8 Ball Game
@client.command(aliases=["8ball"])
async def eightball(ctx, *, question):
    responses = ["It is certain.",
                "It is decidedly so.",
                "Without a doubt.",
                "Yes - definitely.",
                "You may rely on it.",
                "As I see it, yes.",
                "Most likely.",
                "Outlook good.",
                "Yes.",
                "Signs point to yes.",
                "Reply hazy, try again.",
                "Ask again later.",
                "Better not tell you now.",
                "Cannot predict now.",
                "Concentrate and ask again.",
                "Don't count on it.",
                "My reply is no.",
                "My sources say no.",
                "Outlook not so good.",
                "Very doubtful."]
    await ctx.send(f" :8ball: Question: {question} \n:8ball: Answer: {random.choice(responses)}")

#Kick Command
@client.command()
async def kick(ctx, member:discord.Member, *, reason=None):
    await member.kick(reason=reason)
    await ctx.send(f"{member.mention} Kicked! See You Later Alligator :knife: :dizzy_face: :skull: :ambulance: ")

#Ban Command
@client.command()
async def ban(ctx, member:discord.Member, *, reason=None):
    await member.ban(reason=reason)
    await ctx.send(f"{member.mention} Banned! Say Your Goodbyes :ghost: :skull: :coffin: :headstone:")

#Unban Command
@client.command()
async def unban(ctx, *, member):
    banned_users = await ctx.guild.bans()
    member_name, member_discriminator = member.split("#")

    for ban_entry in banned_users:
        user = ban_entry.user

        if(user.name, user.discriminator) == (member_name, member_discriminator):
            await ctx.guild.unban(user)
            await ctx.send(f"{user.mention} Came Back To Life :zombie: ")
            return

#Clear Messages Command
@client.command()
async def clear(ctx, amount = 11):
    if (not ctx.author.guild_permissions.manage_messages):
        await ctx.send("ha ha you thought. need permissions baby")
        return
    amount+=1
    if amount > 101:
        await ctx.send("cant delete more than 100")
    else:
        await ctx.channel.purge(limit = amount)
        await ctx.send("asta la vista messages")

@client.command()
async def mute(ctx, member: discord.Member, *, reason=None):
    if (not ctx.author.guild_permissions.manage_messages):
        await ctx.send("ha ha you thought. need permissions baby")
        return
    guild=ctx.guild
    muteRole = discord.utils.get(guild.roles, name="Muted")

    if not muteRole:
        muteRole = await guild.create_role(name="Muted")

        for channel in guild.channels:
            await channel.set_permissions(muteRole, speak=False, send_messages=False, read_message_history=True, read_messages=True)
        await member.add_roles(muteRole, reason=reason)
        await ctx.send(f"ive shut {member.mention} up")
        await member.send(f"**The Great One** has muted you from: **{guild.name}** | Reason: **{reason}**")


@client.command()
async def unmute(ctx, member: discord.Member, *, reason=None):
    if (not ctx.author.guild_permissions.manage_messages):
        await ctx.send("ha ha you thought. need permissions baby")
        return
    guild = ctx.guild
    muteRole = discord.utils.get(guild.roles, name="Muted")

    if not muteRole:
        await ctx.send(f"{member.mention} you may speak")
        return

    await member.remove_roles(muteRole, reason=reason)
    await ctx.send(f"you may speak {member.mention} ")
    await member.send(f"**The Great One** is sorry for muting you from **{guild.name}** | Reason: **{reason}**")

i had to reset my computer because of wifi troubles and reinstalled everything and that fixed it

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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