首页 > 解决方案 > 嵌入形式的不和谐私人消息不起作用

问题描述

我想创建一个命令,使用 .helpDM 向用户发送嵌入的帮助

如您所见,我以事件形式尝试过。

@client.event                                              
async def on_message(helpDM):

    embed=discord.Embed(title='Hello',colour = discord.Colour.orange())

    embed.add_field(name='Bomb', value=f'Deletes Messages in chat\n .bomb 100', inline=False)
    embed.add_field(name='Luck', value=f'Like 8ball fourtune teller', inline=False)
    embed.add_field(name='Tof', value=f'True or False', inline=False)
    embed.add_field(name='Hitme', value=f'See me holy face', inline=False)
    embed.add_field(name='Monkey', value=f'Random pic of monkey monkey', inline=False)
    embed.add_field(name='Whois', value=f'Userinfo', inline=False)
    embed.add_field(name='coin', value=f'Flips a coin', inline=False)
    embed.add_field(name='Dice', value=f'Random number from 1 to 6', inline=False)
    embed.add_field(name='Randomnumber', value=f'Gives you a random number from 1 to 100', inline=False)
    embed.add_field(name='Meme', value=f'Random meme?', inline=False)
    embed.add_field(name='Say', value=f'Says what ever you want the bot to say', inline=False)
    embed.add_field(name='Kick', value=f'Kicks user (Needs Admin)', inline=False)
    embed.add_field(name='Ban', value=f'Bans user (Needs Admin', inline=False)
    embed.add_field(name='Unban', value=f'Revokes ban from user. (Needs Admin)', inline=False)
    embed.add_field(name='Prefix', value=f'Changes prefix e.g .prefix !', inline=False)

    await client.send_message(embed=embed)
    # cllient.whisper wont work to

命令形式:

@client.command()
async def helpDMM(ctx, member: discord.Member=None):

    embed=discord.Embed(title='Hello',colour = discord.Colour.orange())

    embed.add_field(name='Bomb', value=f'Deletes Messages in chat\n .bomb 100', inline=False)
    embed.add_field(name='Luck', value=f'Like 8ball fourtune teller', inline=False)
    embed.add_field(name='Tof', value=f'True or False', inline=False)
    embed.add_field(name='Hitme', value=f'See me holy face', inline=False)
    embed.add_field(name='Monkey', value=f'Random pic of monkey monkey', inline=False)
    embed.add_field(name='Whois', value=f'Userinfo', inline=False)
    embed.add_field(name='coin', value=f'Flips a coin', inline=False)
    embed.add_field(name='Dice', value=f'Random number from 1 to 6', inline=False)
    embed.add_field(name='Randomnumber', value=f'Gives you a random number from 1 to 100', inline=False)
    embed.add_field(name='Meme', value=f'Random meme?', inline=False)
    embed.add_field(name='Say', value=f'Says what ever you want the bot to say', inline=False)
    embed.add_field(name='Kick', value=f'Kicks user (Needs Admin)', inline=False)
    embed.add_field(name='Ban', value=f'Bans user (Needs Admin', inline=False)
    embed.add_field(name='Unban', value=f'Revokes ban from user. (Needs Admin)', inline=False)
    embed.add_field(name='Prefix', value=f'Changes prefix e.g .prefix !', inline=False)
    
    await client.whisper(embed=embed)

错误,

await client.send_message(embed=embed) AttributeError: 'Bot' object has no attribute 'send_message'

请注意,耳语也是如此……

标签: pythonpython-3.xdiscordbotsdiscord.py

解决方案


使用 discord.py 重写版本,您应该使用<channel>.send()而不是<channel>.send_message()

参考


推荐阅读