'How to make bot respond without prefix in certain situation while still responding to other commands in discord.py
I'm making a game using discord.py and the bot has a few commands already, but once the game itself starts I want users to be able to input answers without requiring a prefix but I'm not sure how to do this. I tried using on_message for this situation to immediately, and while I'm pretty sure the on_message subroutine works how I want, adding it causes the other subroutines to stop being executed. Is there another way to do this? Here's a bit of the code:
bot = commands.Bot(command_prefix="-") #sets the bot prefix
@bot.event
async def on_message(ctx): #accepts all answers without needing a command
if len(playerQuestions[0]) == True and (str(ctx.channel.name) == channels[0] or str(ctx.channel.name) == channels[1]):
await guess(ctx, ctx.content)
@bot.command()
async def join(ctx): #subroutine for the join command - allows users to join the lobby before the game begins
if gameInProgress == True: #blocks the command from being used if a game is in progress
await ctx.send("There is currently a game in progress, so this action cannot currently be performed.")
else:
response = ""
flag = False
for i in range(0, len(players)): #compares sender of message to each player in the lobby to check if user is already in the lobby
if ctx.author == players[i]:
await ctx.channel.send("You are already in the lobby")
flag = True
if flag == False: #adds the user to the lobby if not already in and announces it
players.append(ctx.author)
response = (ctx.author.mention) + " has joined the lobby. \n"
response = response + (str(len(players)) + " in lobby. \n")
await ctx.send(response)
so if someone types "-join" and the requirements therefore aren't met in the on_message subroutine, how could I make the program execute the code in the join subroutine?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
