I'm coding a Discord bot in PyCharm, and I'm working on a mute command. I've heard a lot that the time module is already installed by default and you don't need to import it. I'm starting to think the opposite.
import discord
from discord.ext import commands
from discord.ext.commands import MissingPermissions
client = commands.Bot(command_prefix = "$")
@client.event
async def on_ready():
print('Bot is ready')
await client.change_presence(status=discord.Status.online, activity=discord.Game("$help"), afk = False)
@client.command()
@commands.has_permissions(administrator = True)
async def mute(ctx, member : discord.Member, *, amount = 60, reason = "No reason provided."):
guild = client.guilds[0]
mutedRole = discord.utils.get(guild.roles, name = "Muted")
if not mutedRole:
mutedRole = await guild.create_role(name = "Muted")
for channel in guild.channels:
await channel.set_permissions(mutedRole, speak = False, send_messages = False, read_message_history = True, read_messages = False)
await member.add_roles(mutedRole, reason=reason)
await member.send(f"You have been muted for {amount} seconds from {ctx.guild.name}. Reason = "+reason)
await ctx.send(f"Muted {discord.Member} for {amount} seconds from {ctx.guild.name}. Reason = "+reason)
time.sleep(amount)
await member.remove_roles(mutedRole)
await member.send(f"You have been unmuted from {ctx.guild.name}")
await ctx.send(f"{discord.Member} has been unmuted from {ctx.guild.name}")
So the idea was the bot would mute that member, and then the time.sleep(amount) would sleep for the given amount of time of the member being muted, then would wake up and unmute the member. Well, this error came.
I really don't want to delete another command that I worked so hard on.