有谁知道如何解决这个 discord.py 错误
does anyone know how to fix this discord.py error
我一直收到这个错误。一切都正确导入,一切都已安装。代码在原子中工作,然后突然间我得到了这个错误。 pycharm 一切正常。 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}**")
由于 wifi 问题,我不得不重置我的电脑并重新安装所有内容并修复它
我一直收到这个错误。一切都正确导入,一切都已安装。代码在原子中工作,然后突然间我得到了这个错误。 pycharm 一切正常。 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}**")
由于 wifi 问题,我不得不重置我的电脑并重新安装所有内容并修复它