我想通过命令启用慢速模式,格式为>slowmode <seconds>
,例如>slowmode 10
。我当前的代码:
@has_permissions(manage_channels=True)
async def slowmode(ctx, amount):
await ctx.channel.edit.slowmode.delay(int(amount))
我得到这个错误:
Ignoring exception in command slowmode:
Traceback (most recent call last):
File "C:\Users\dante\AppData\Local\Programs\Python\Python37-32\lib\site-packages\discord\ext\commands\core.py", line 83, in wrapped
ret = await coro(*args, **kwargs)
File "C:\Users\dante\Desktop\Utilly\Utilly.py", line 116, in slowmode
await ctx.channel.edit.slowmode.delay(int(amount))
AttributeError: 'function' object has no attribute 'slowmode'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:\Users\dante\AppData\Local\Programs\Python\Python37-32\lib\site-packages\discord\ext\commands\bot.py", line 892, in invoke
await ctx.command.invoke(ctx)
File "C:\Users\dante\AppData\Local\Programs\Python\Python37-32\lib\site-packages\discord\ext\commands\core.py", line 797, in invoke
await injected(*ctx.args, **ctx.kwargs)
File "C:\Users\dante\AppData\Local\Programs\Python\Python37-32\lib\site-packages\discord\ext\commands\core.py", line 92, in wrapped
raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: AttributeError: 'function' object has no attribute 'slowmode'
答案 0 :(得分:1)
使用discord.TextChannel.edit(slowmode_delay=amount)
@has_permissions(manage_channels=True)
async def slowmode(ctx, amount):
try:
await ctx.channel.edit(reason='Bot Slowmode Command', slowmode_delay=int(amount))
except discord.Errors.Forbidden:
await ctx.send('I do not have the permission to do this, please try again')