如果可能,我如何使用我的 .dm 命令 DM 与我的机器人有共同服务器的人? (不和谐.py)

时间:2021-08-01 21:29:07

标签: python python-3.x discord.py

当人们想使用我的反馈命令提供有关机器人的反馈时,我希望能够通过机器人将他们发回,但我的 DM 命令不起作用,即使他们与机器人有共同的服务器。当我运行该命令时,出现此错误:/usr/lib/python3.7/asyncio/events.py:88: RuntimeWarning: coroutine 'Client.fetch_user' was never awaited。谁能帮我这个?这是我的代码:

@client.command(description="This command DMs people and can only be used by the owner.")
@commands.is_owner()
async def dm(ctx, id, *, message):
    user = await client.fetch_user(id)
    await user.send(message)
    return

1 个答案:

答案 0 :(得分:0)

@client.command(description="This command DMs people and can only be used by the owner.")
@commands.is_owner()
async def dm(ctx, member: discord.Member = None):
    if member == None:
        await ctx.send("Mention the user or provide user id of the user you want me to send a DM to.")

    else:
        embed=discord.Embed(title=f"Sure, What do you want me to send to {member.display_name} ?", description="write anything here")
        await ctx.send(embed=embed)
        def check(m):
            return m.author.id == ctx.author.id
        message = await client.wait_for('message', check=check)
        await ctx.send(f'Message sent to {member.display_name}!')
    
        await member.send(f"{ctx.author.mention} Sent a message - \n{message.content}")