I’m working on a Discord bot for my trading community that should send notifications when I make trades. The bot starts up fine and shows no error messages in the terminal, but it completely ignores my !notify commands.
I’ve double checked all the bot settings in Discord’s developer portal and made sure the permissions are correct in my server. Here’s my code:
import discord
from discord.ext import commands
intents = discord.Intents.default()
client = commands.Bot(command_prefix='!', intents=intents)
@client.event
async def on_ready():
print(f'Bot is online as {client.user}')
@client.command()
async def notify(ctx, trade_action, ticker, strike, contract_type, exp_date, cost):
# Check if user has the required role
if "traders" in [r.name for r in ctx.author.roles]:
# Build the notification embed
notification = discord.Embed(title="Trade Notification", color=0xff0000)
notification.add_field(name="Action", value=trade_action, inline=False)
notification.add_field(name="Ticker", value=ticker, inline=False)
notification.add_field(name="Strike", value=strike, inline=False)
notification.add_field(name="Type", value=contract_type, inline=False)
notification.add_field(name="Expiry", value=exp_date, inline=False)
notification.add_field(name="Cost", value=cost, inline=False)
# Post to the alerts channel
for server in client.guilds:
for ch in server.text_channels:
if ch.name == 'trade-alerts':
await ch.send(embed=notification)
# Send DM to all traders
for server in client.guilds:
for user in server.members:
if "traders" in [r.name for r in user.roles]:
await user.send(embed=notification)
client.run('your-bot-token')