没有其他用户的Python Discord私人消息

时间:2020-08-03 15:33:02

标签: python discord discord.py

await self.client.get_user(user id).send(msg)

当我为自己的一个帐户输入用户ID时,它起作用了 但是当我使用我的朋友时,它说AttributeError

AttributeError: 'NoneType' object has no attribute 'send'

机器人需要私下向其他人(用户ID)发消息

@client.command()
async def DM(ctx,  message): 
userid = 'stored here
await self.client.get_user(user id).send(msg)

2 个答案:

答案 0 :(得分:0)

您可能输入了错误的ID。尝试类似

@bot.command()
async def get_id(ctx, *, user: discord.User):
    await ctx.send(str(user.id))

以获取正确的ID。您可以这样称呼!get_id @MyFriend

答案 1 :(得分:0)

如果您希望向用户发送消息,这可能会有所帮助

@bot.command()
async def dm(ctx, member: discord.Member, *, message)
    await member.send(message)