因此,我已经用discord机器人发出了一条帮助命令,当我将其作为嵌入消息发送时,它看起来更加简洁。但是,它确实占用了大量空间,因此我想知道是否可以将它作为DM发送给message.author
。这是我到目前为止的内容:
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")
但是,运行命令后,您将收到错误“ NameError:未定义名称'消息'。”即使我将message.author
部分替换为message.channel
,此错误消息仍然会出现。完全可以发送消息的唯一方法是将bot.send_message
替换为await bot.say(embed=embed)
。有办法解决吗?
答案 0 :(得分:1)
您没有直接引用message
。您必须从要传递的Context
对象中获取它。
@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)