我正在 PyCharm 中编写一个 Discord 机器人,并且正在研究静音命令。我经常听说时间模块已经默认安装,你不需要导入它。我开始有相反的想法。
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}")
因此,我们的想法是机器人将该成员静音,然后 time.sleep(amount) 将休眠该成员静音的给定时间,然后唤醒并取消该成员的静音。嗯,这个错误来了。
我真的不想删除另一个我费尽心血的命令。