Reputation: 58
I am triying to develop a game using a discord bot. Im having trouble dealing with the onmessage routine.. I need it only to "listen" one specific channel, not all the server.. by now I did the following:
@client.event
async def on_message(message):
global rojo
global IDS
canal = IDS['C_Juego']
if message.author == client.user or str(message.channel) != IDS['C_Juego']:
return
else:
if(rojo == 1):
autor = message.author
await message.add_reaction("🔴")
await message.channel.send("Player: " + str(autor) + " removed!")
role = get(message.guild.roles, name="Jugador")
await message.author.remove_roles(role)
elif(str(message.channel) == IDS['C_Juego']):
await message.add_reaction("🟢")
print("verde")
What's going on? when I enable this function .. the rest of my commands stop having effect (in any channel of the server) in addition to the fact that this function is called by each message sent....
I explain the context: It is a game in which while listening to a song the players must place different words under a theme, when the music stops, if someone writes they are eliminated.
Commands definitios: I have plenty command definitios... which works fine until I add this problematic function.. I add as example two of them:
@client.command()
@commands.has_role("Owner")
async def clear(ctx):
await ctx.channel.purge()
@client.command()
@commands.has_role("Owner")
async def swipe(ctx, role: discord.Role):
print(role.members)
for member in role.members:
await member.remove_roles(role)
await ctx.send(f"Successfully removed all members from {role.mention}.")
Upvotes: 0
Views: 157
Reputation: 165
Overriding the default provided on_message forbids any extra commands from running. To fix this, add a bot.process_commands(message) line at the end of your on_message.
@client.event
async def on_message(message):
# do what you want to do here
await client.process_commands(message)
Upvotes: 2