【问题标题】:How can I get my discord bot to DM a member and myself? [duplicate]我怎样才能让我的不和谐机器人 DM 成员和我自己? [复制]
【发布时间】:2020-04-15 02:56:24
【问题描述】:

如果可能的话,我如何让我的 discord 机器人(在 python 中)向另一个用户和发送命令的人发送消息(告诉他们他们说了什么)?

编辑:已解决,感谢 Patrick Haugh - https://stackoverflow.com/users/6779307/patrick-haugh 顺便说一句,这是我的代码,以防其他人遇到同样的问题:

@client.command()
async def dm(ctx, user: discord.User, *, message=None):
    if message == None:
        await ctx.send('You need to put a message')
    else:
        await user.send(message)
        await ctx.channel.purge(limit=1)
        await ctx.send('DM Sent')
        await ctx.author.send('"' + message + '"' + ' sent to ' + str(user))
        # just so i can see every dm (a bit creepy ik but hey it's my bot so i'll do it)
        print('"' + message + '"' + ' sent to ' + str(user))

【问题讨论】:

  • 如果您试图让两个用户与机器人进行私人聊天,我很确定 Discord 不允许这样做。 ClientUser.create_group 的文档说机器人帐户不能使用它。
  • 不,我希望它给一个用户 dm,然后 dm 使用该命令的人告诉他们他们说了什么,我在解释事情时很垃圾,所以我只说我想要它做的步骤1。人键入命令'.dm @user'message' 2. bot dms 用户 3. bot 清除人员文本 4. bot 在聊天中说 'DM Sent' 5. bot dms 人说他们想得到什么 dmed rn i只有步骤 1-4
  • 我当前的代码是@client.command() async def dm(ctx, user: discord.User, *, message=None):` if message == None: await ctx.send('You need to put a message') else: await user.send(message) await ctx.channel.purge(limit=1) await ctx.send('DM Sent')

标签: python bots discord discord.py-rewrite dm


【解决方案1】:

以下代码 sn-p 应该可以回答您的问题:

async def on_message(self, message):
    await message.author.send("Content")
    await client.get_user(other_user_id).send("Content")

【讨论】:

    猜你喜欢
    • 2022-11-11
    • 2021-07-09
    • 1970-01-01
    • 2021-07-24
    • 2018-04-18
    • 2021-03-07
    • 2013-03-17
    • 2019-06-14
    • 2014-06-22
    相关资源
    最近更新 更多