Here's the answer I wrote but couldn't post:
You cannot have 2 on_message
event listeners. You can merge the two event listeners and their responses by using if...elif
like this instead:
@bot.event
async def on_message(message): #When any message is sent
if message.content.startswith('-coinflip'):
embedVar = discord.Embed(
title="Toss",
description=f'You got {random.choice(heads_tails)}',
color=(0xFF0000))
print(f'-coinflip command used by {message.author}')
await message.channel.send(embed=embedVar)
elif message.content.startswith('-help'):
embedVar = discord.Embed(
title="Help arrived!",
description="So, it looks like you need help, let me help you",
colour=0xFF0000)
embedVar.add_field(name="Bot Prefix", value="-", inline=False)
embedVar.add_field(name="Moderation Commands",
value="-help",
inline=True)
embedVar.add_field(name="Fun commands", value="-coinflip", inline=True)
embedVar.set_thumbnail(
url="https://media.discordapp.net/attachments/923531605660815373/974248483479494686/charizard-mega-charizard-y.gif")
print(f'-help command used by {message.author}')
await message.channel.send(embed=embedVar)
elif
is the same as else if
; in this case, if the message's content
doesn't start with "-coinflip" and starts with "-help", it creates and sends an Embed
.
I've replaced the heads_tails
variable for a fully-functioning code:
from discord.ext import commands
import discord
import discord.utils
import random
intent = discord.Intents(messages=True, message_content=True, guilds=True)
bot = commands.Bot(command_prefix="", description="", intents=intent)
heads_tails = ("Heads", "Tails") #Replace this with your sequence
@bot.event
async def on_ready(): #When the bot comes online
print("It's online.")
@bot.event
async def on_message(message): #When any message is sent
if message.content.startswith('-coinflip'):
embedVar = discord.Embed(
title="Toss",
description=f'You got {random.choice(heads_tails)}',
color=(0xFF0000))
print(f'-coinflip command used by {message.author}')
await message.channel.send(embed=embedVar)
elif message.content.startswith('-help'):
embedVar = discord.Embed(
title="Help arrived!",
description="So, it looks like you need help, let me help you",
colour=0xFF0000)
embedVar.add_field(name="Bot Prefix", value="-", inline=False)
embedVar.add_field(name="Moderation Commands",
value="-help",
inline=True)
embedVar.add_field(name="Fun commands", value="-coinflip", inline=True)
embedVar.set_thumbnail(
url="https://media.discordapp.net/attachments/923531605660815373/974248483479494686/charizard-mega-charizard-y.gif")
print(f'-help command used by {message.author}')
await message.channel.send(embed=embedVar)
Also, is "-help" a moderation command? And, try searching for and solving such problems yourself. StackOverflow shouldn't be the first place to ask such questions.