0

Disocord.py Rewrite
Error: No
The command below is not working as expected

@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))

The p/ is the bots prefix, This code above tells (Write this command in {}'.format(er.mention)) when used p/ in the right channl the bot doesn't say anything but i use any command like p/help it doesn't works.actually The event should allow members use bot commands (@bot.command) only in the channel specified not any other channel but the thing is no commands work in the channel specified nor in any channel in the server. Any help would be great :) Edit: (Specified my question and made it a bit clear)

bos gamer
  • 113
  • 1
  • 2
  • 13

1 Answers1

2

Edit:
From the comments, you may actually want something like

@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))
Anu6is
  • 2,137
  • 2
  • 7
  • 17
  • That works but my other command like /help and others don't work in any channel – bos gamer Apr 15 '19 at 03:58
  • I think you need to clarify your question. From what I understood, you wanted ALL commands to only work in a specific channel.Your question stated **"The command should not allow members to use bot commands in any channel except the channel specified but when the member uses the command in the right the channel the command must work"**. The solution presented does just that. It makes it so that ALL commands can only be executed in the channel specified. – Anu6is Apr 15 '19 at 10:14
  • Yes i mean that – bos gamer Apr 15 '19 at 11:53
  • So then what do you mean by "help" does not work in any channel? Does it not work at all? It does not work in the specific channel and it doesn't work in any other channel? – Anu6is Apr 15 '19 at 12:03
  • Yes the help command doesn't work at all and rest of my commands too, when i remove that command above i gave the commands start working again **Also i mean't by all of my commands made** – bos gamer Apr 15 '19 at 12:18
  • I see that you edited your question, however it is still not very clear. Can you include the code that works as well as the code that does not work. – Anu6is Apr 15 '19 at 12:25
  • The code above works that it says to write p/ thing (p/ is the bots prefix) in a specific channel but when someone write for ex p/help or p/rps or p/8ball none of them works (also all those commands i have made are correct no errors on them 100% sure) it is just the command above stopping my other commands to work – bos gamer Apr 15 '19 at 12:28
  • I added and edit to my answer, with what I think you are aiming for – Anu6is Apr 15 '19 at 13:00
  • @bosgamer See [Why does on_message stop commands from working?](https://stackoverflow.com/questions/49331096/why-does-on-message-stop-commands-from-working) – Patrick Haugh Apr 15 '19 at 15:21
  • @PatrickHaugh thank you i have got the answer thankyou very much – bos gamer Apr 16 '19 at 04:26