【问题标题】:Can't Make A Command Only For specific Channel不能只对特定频道发出命令
【发布时间】:2019-09-03 22:25:12
【问题描述】:

Disocord.py 重写
错误: 否
以下命令未按预期工作

@bot.event
async def on_message(message):
    x = (559253532759425044)
    er = bot.get_channel(559253532759425044)
    if not message.channel.id != x:
        return
    else:
        if "p/" in message.content.lower():
            await message.channel.send('Write this command in {}'.format(er.mention))

p/是bots前缀,上面这段代码告诉(在{}'.format(er.mention)中写这个命令)什么时候使用p/正确的 channl 机器人什么也没说,但我使用任何命令,如 p/help 它不起作用。实际上该事件应该允许成员使用机器人命令 (@bot.command)仅在指定的频道中,而不是任何其他频道,但事情是没有命令在指定的频道或服务器中的任何频道中起作用。任何帮助都会很棒:) 编辑:(指定我的问题并说清楚)

【问题讨论】:

  • if not message.channel.id != x: 你这里有一个双重否定 not message.channel.id not 等于 x。它应该只是 if message.channel.id != x - 删除 not。
  • x也不需要括号中的频道ID
  • 不明白你所说的,先生,你能不能更深入地解释一下,我也想要它,就像我不必在我做的每个命令中写东西一样
  • 当你说命令时,是不是指commands扩展,即用@bot.command装饰的协程?
  • 是的,我的意思是@bot.command

标签: bots discord discord.py-rewrite


【解决方案1】:

编辑:
从 cmets 中,您实际上可能想要类似

@bot.event
async def on_message(message):
    cmdChannel = bot.get_channel(559253532759425044)
    if message.content.lower().startswith('p/'):
        if message.channel.id == cmdChannel.id:
            #command invoked in command channel - execute it
            await bot.process_commands(message)
        else:
            #command attempted in non command channel - redirect user
            await message.channel.send('Write this command in {}'.format(cmdChannel.mention))

【讨论】:

  • 可以,但是我的其他命令(例如 /help 和其他命令)在任何频道中都不起作用
  • 我认为您需要澄清您的问题。据我了解,您希望所有命令仅在特定频道中起作用。您的问题指出 “该命令不应允许成员在指定频道之外的任何频道中使用机器人命令,但是当成员在正确的通道命令必须工作”。提出的解决方案就是这样做的。它使得所有命令只能在指定的通道中执行。
  • 是的,我的意思是
  • 那么“帮助”在任何渠道都不起作用是什么意思?它根本不起作用吗?在特定频道不起作用,在任何其他频道都不起作用?
  • 是的,帮助命令根本不起作用,我的其他命令也不起作用,当我删除上面的命令时,我给出的命令又开始工作了 我的意思不是我所有的发出的命令
猜你喜欢
  • 2019-01-16
  • 1970-01-01
  • 2021-09-22
  • 2021-11-18
  • 1970-01-01
  • 2021-05-02
  • 2018-12-01
  • 2022-01-24
  • 2020-12-26
相关资源
最近更新 更多