首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何通过命令启用慢模式?

如何通过命令启用慢模式?
EN

Stack Overflow用户
提问于 2020-05-31 23:00:47
回答 1查看 477关注 0票数 1

我想通过一个命令来启用慢模式,命令的形式是>slowmode <seconds>,比如>slowmode 10。我当前的代码:

代码语言:javascript
复制
 @has_permissions(manage_channels=True)
 async def slowmode(ctx, amount):
    await ctx.channel.edit.slowmode.delay(int(amount))

我得到了这个错误:

代码语言:javascript
复制
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'
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-05-31 23:04:17

使用discord.TextChannel.edit(slowmode_delay=amount)

代码语言:javascript
复制
@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')
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62118065

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档