将消息发送给消息中指定的特定用户discord.py [英] Sending a message to a specific user specified in the message, discord.py

查看:40
本文介绍了将消息发送给消息中指定的特定用户discord.py的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的discord.py代码中,我试图向消息作者指定的用户设置一条简单的发送消息.

In my discord.py code I am trying to set up a simple send message to a user that the message author has specified.

    if message.content.startswith('!hello'):
  print("Hello DIRECT MESSAGE")
  msg = "Why hello there"
  print (message.author)
  await client.send_message(message.author, msg)

if message.content.startswith('!poke'):
  print("Poke DIRECT MESSAGE")
  a = message.content[6:]
  print(a)
  msg = "Hi there"
  await client.send_message(a, msg)

!hello命令可以正常工作,但是在将用户ID作为字符串接收后,我不知道如何将用户ID作为对象发送给send message命令.

The !hello command works fine, but I do not know how to get the User ID as an object for the send message command after receiving their ID as a string.

推荐答案

使用假设这是在服务器中发生的,其中命令调用者和目标都是: target = discord.utils.get(message.server.members,id = a)

Assuming this is happening in a server, where both the command invoker and the target are: target = discord.utils.get(message.server.members, id=a)

这篇关于将消息发送给消息中指定的特定用户discord.py的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆