0
votes

So, I have made a help command with my discord bot and it looks much more neat when I send it as an embed message. However, it does take up a lot of space, so I was wondering if I could send it as a DM to the message.author. Here's what I have so far:

import discord
from discord.ext.commands import Bot
from discord.ext import commands

Client = discord.Client()
bot_prefix = "."
bot = commands.Bot(command_prefix=bot_prefix)

@bot.event
async def on_ready():
    print("Bot Online!")
    print("Name: {}".format(bot.user.name))
    print("ID: {}".format(bot.user.id))

bot.remove_command("help")

# .help
@bot.command(pass_context=True)
async def help(ctx):
embed=discord.Embed(title="Commands", description="Here are the commands:", color=0xFFFF00)
embed.add_field(name="Command1", value="What it does", inline= True)
embed.add_field(name="Command2", value="What it does", inline= True)
await bot.send_message(message.author, embed=embed)

bot.run("TOKEN")

However after running the command you get the error "NameError: name 'message' not defined." This error message still shows up even if I replace the message.author part with message.channel. The only way I can get the message to send at all is when I replace the bot.send_message with await bot.say(embed=embed). Is there a way around this?

1

1 Answers

1
votes

You don't have a direct reference to the message. You have to get it from the Context object you're passing.

@bot.command(pass_context=True)
async def help(ctx):
    embed=discord.Embed(title="Commands", description="Here are the commands:", color=0xFFFF00)
    embed.add_field(name="Command1", value="What it does", inline= True)
    embed.add_field(name="Command2", value="What it does", inline= True)
    await bot.send_message(ctx.message.author, embed=embed)