所以,我已经使用我的discord bot发出了一个帮助命令,当我将它作为嵌入消息发送时,它看起来更加整洁。但是,它确实占用了很多空间,所以我想知道我是否可以将它作为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:name'消息'未定义。”即使我用message.author
替换message.channel
部分,此错误消息仍然显示。我可以获得发送消息的唯一方法是当我用bot.send_message
替换await bot.say(embed=embed)
时。有没有解决的办法?
您没有直接引用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)