python - 如何在 discord.py 中向特定标签发送消息?
问题描述
这是我尝试过的:
import discord
client = discord.Client()
@client.event
async def on_ready():
print("Logged in as: {}".format(client.user))
user = client.get_user('741143876563370086')
await user.send("Hi")
client.run('token')
但是,它没有用。我知道有一个类似的问题,但是那个问题使用了一个命令,而我只想发送给特定的用户。
编辑:我用一些新代码编辑了它
解决方案
可悲的是,您需要首先启用意图,与其他命令不同,此命令在on_ready
事件上与 dm 用户不同。您可以在https://discord.com/developers/applications上启用它们,然后转到您的机器人,然后在下面的这张图片上启用它们(对不起,糟糕的圈子事情 lmao)
现在您启用了这些功能,您就可以开始编码了。
我们把我们的意图放在首位client
intents = discord.Intents(messages = True, members = True)
client = commands.Client(intents = intents)
有关意图的更多信息将显示在这里
好的,关于on_ready
事件:
@client.event
async def on_ready():
print("We are logged in as: {}".format(client.user.name))
user = client.get_user(User_Id_Here) # You need to copy your user ID to make it work
await user.send('Your Message Here') # Your message here, something like "Logged in!"
它对我有用。常见问题解答:我如何发送 DM?
稍后谢谢我 :D
推荐阅读
- angular - Firestore 的离子问题“存储在 Firestore 中的 Date 对象的行为将会改变”
- python - 蟒蛇 | 制作一个文件并在每次运行时增加名称
- google-apps-script - Google 脚本和 Alphavantage json 查询:TypeError:无法读取属性
- mysql - Querydsl 和 MySQL - distancesphere 不存在
- excel - VBA 条件格式打印格式
- oracle10g - 如何在对三个不同列具有相同检查条件的 SELECT 查询中优化 CASE 语句
- r - 从一个整数向量,构建一个更长的向量,包括与原始整数的距离最多为 10 的所有整数
- excel - VBA 宏将图表从 Excel 粘贴到 Word 中,并使用文本换行设置格式
- java - 如何一次加载多个 Admob 广告并在队列中显示
- javascript - 查找元素内的所有@tagnames,然后在其上插入一个链接