【发布时间】:2018-12-10 04:34:54
【问题描述】:
所以,我用我的不和谐机器人发出了一个帮助命令,当我将它作为嵌入消息发送时它看起来更加整洁。但是,它确实占用了很多空间,所以我想知道是否可以将其作为 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' not defined。”即使我将message.author 部分替换为message.channel,此错误消息仍然会出现。我可以让消息发送的唯一方法是将bot.send_message 替换为await bot.say(embed=embed)。有没有办法解决这个问题?
【问题讨论】:
标签: python bots discord discord.py