【发布时间】: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