我正在制作一个用于不和谐的机器人,我想要一个自定义的帮助消息。我试过了:
from discord.ext import commands
bot = commands.Bot(command_prefix="!")
@bot.command()
async def help(ctx):
member = ctx.author
await ctx.send(member, "test successful")
bot.run('TOKEN')
它应该向用户发送私人消息并向他们发送任何内容。但是当我输入 !help
时,机器人甚至没有对消息做出反应。
答案 0 :(得分:1)
发送消息只有一个位置参数(消息本身)和选项。要发送 DM 消息,您需要改为在成员类上发送。
await member.send("test successful")
答案 1 :(得分:0)
在定义您的 bot
时,默认是有一个自动帮助命令。 commands.Bot
有一个关键字参数 help_command
,您可以将其设置为 None
以确保关闭自动帮助命令。此外,要向某人发送直接消息,您必须使用 user.send()
。您的原始命令还要求您提及用户,因为它使用 Member
作为参数。我不确定这是否是您想要的,但我不这么认为。
这是我会做的:
bot = commands.Bot(command_prefix="!",help_command=None)
@bot.command()
async def help(ctx):
await ctx.author.send("test successful")
编辑:我的解释清晰。