I am having a problem where when I make more than one Embed on Discord.py, the first command doesn't respond but the second one does.
Here's my code:
import discord
from discord.ext import commands
client = commands.Bot(command_prefix = '.')
@client.event
async def on_ready():
await client.change_presence(status=discord.Status.online, activity=discord.Game('private'))
print('bot is online')
@client.event
async def on_message(message):
if message.content.startswith('.kade'):
embedVar = discord.Embed(title="Kade Engine Download", description="Downloads for Kade Engine 1.8", color=0x2C93FA)
embedVar.add_field(name="Kade Engine Installation", value="https://github.com/KadeDev/Kade-Engine/releases/tag/1.8", inline=False)
embedVar.add_field(name="Kade Engine Source (Recommended for Mod Makers)", value="https://github.com/KadeDev/Kade-Engine", inline=False)
await message.channel.send(embed=embedVar)
@client.event
async def on_message(message):
if message.content.startswith('.week'):
embedVar = discord.Embed(title="How to make a week", description="How to make a week", color=0x2C93FA)
embedVar.add_field(name="test", value="test", inline=False)
embedVar.add_field(name="test", value="test", inline=False)
await message.channel.send(embed=embedVar)
client.run('WONT SHOW BOT TOKEN')
Could someone please help me with this?
CodePudding user response:
When you are creating an on_message()
event you shouldn't create it multiple times. Create one and make multiple if/elif
statements or use commands which give you more capabilities.
Your fixed code with on_message()
(delete both on_message
events and replace with):
@client.event
async def on_message(message):
if message.content.startswith('.kade'):
embedVar = discord.Embed(title="Kade Engine Download", description="Downloads for Kade Engine 1.8", color=0x2C93FA)
embedVar.add_field(name="Kade Engine Installation", value="https://github.com/KadeDev/Kade-Engine/releases/tag/1.8", inline=False)
embedVar.add_field(name="Kade Engine Source (Recommended for Mod Makers)", value="https://github.com/KadeDev/Kade-Engine", inline=False)
await message.channel.send(embed=embedVar)
elif message.content.startswith('.week'):
embedVar = discord.Embed(title="How to make a week", description="How to make a week", color=0x2C93FA)
embedVar.add_field(name="test", value="test", inline=False)
embedVar.add_field(name="test", value="test", inline=False)
await message.channel.send(embed=embedVar)
or use commands (recommended):
@client.command()
async def kade(ctx):
embedVar = discord.Embed(title="Kade Engine Download", description="Downloads for Kade Engine 1.8", color=0x2C93FA)
embedVar.add_field(name="Kade Engine Installation", value="https://github.com/KadeDev/Kade-Engine/releases/tag/1.8", inline=False)
embedVar.add_field(name="Kade Engine Source (Recommended for Mod Makers)", value="https://github.com/KadeDev/Kade-Engine", inline=False)
await ctx.send(embed=embedVar)
@client.command()
async def week(ctx):
embedVar = discord.Embed(title="How to make a week", description="How to make a week", color=0x2C93FA)
embedVar.add_field(name="test", value="test", inline=False)
embedVar.add_field(name="test", value="test", inline=False)
await ctx.send(embed=embedVar)