【问题标题】:Python Discord private message without another user没有其他用户的 Python Discord 私人消息
【发布时间】:2020-11-23 16:42:40
【问题描述】:
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)

【问题讨论】:

  • 请提供minimal reproducible example。这至少应该包括有问题的命令和将数据插入数据库的代码。这也有助于了解表的架构,尤其是用户 ID 字段的数据类型。
  • 我刚接触堆栈溢出
  • userid 是您真实代码中的字符串吗?它必须是一个整数。
  • 它是一个整数,问题是它对特定帐户有效,而对另一个帐户无效
  • 你能修改一下,让它单独获取用户ID并打印repr(userid)吗? get_user 找不到具有该 id 的任何人,这通常意味着它有问题

标签: python discord discord.py


【解决方案1】:

您的 ID 可能有误。尝试类似

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

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

【讨论】:

    【解决方案2】:

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

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

    【讨论】:

    • 我并不想提及接收者,反正得到了代码
    • python await self.client.get_user(userid).send("ERROR budget") 这与 discord.py 的问题无关,我的数据库在存储时四舍五入了用户 ID,因此用户 ID 错误
    猜你喜欢
    • 2017-12-24
    • 2020-12-23
    • 2018-07-24
    • 1970-01-01
    • 2020-11-22
    • 2015-03-08
    • 2021-12-28
    • 2020-08-25
    • 2021-04-30
    相关资源
    最近更新 更多