通过 discord.py 中的用户 ID 向某人发送私信
DM to a person by user id in discord.py
我检查了很多答案,但那些答案使用ctx.author.send('something')
。但我想通过用户 ID 发送,而不是 AUTHOR。
这是我的代码:
@bot.command()
async def dm(ctx):
await ctx.send(496021236988510209, 'test')
而且它甚至 return 都没有错误消息。
要获得服务器成员,请使用 Guild.get_member。
还有 Client.fetch_user 仅适用于机器人。
如果它应该工作但没有成员出现,这很可能是因为您在创建 discord 客户端之前忘记说明您使用 members
的意图。例如:
import discord
intents = discord.Intents.default()
intents.members = True
client = discord.Client(intents=intents)
可能重复,here。
您可以使用以下代码:
@client.command()
@commands.has_permissions(manage_roles = True)
async def dm(ctx, users: Greedy[User], *, message):
for user in users:
await user.send(message)
你直接私信@3422353423342 消息
@3422353423342代表一个用户id
我检查了很多答案,但那些答案使用ctx.author.send('something')
。但我想通过用户 ID 发送,而不是 AUTHOR。
这是我的代码:
@bot.command()
async def dm(ctx):
await ctx.send(496021236988510209, 'test')
而且它甚至 return 都没有错误消息。
要获得服务器成员,请使用 Guild.get_member。
还有 Client.fetch_user 仅适用于机器人。
如果它应该工作但没有成员出现,这很可能是因为您在创建 discord 客户端之前忘记说明您使用 members
的意图。例如:
import discord
intents = discord.Intents.default()
intents.members = True
client = discord.Client(intents=intents)
可能重复,here。
您可以使用以下代码:
@client.command()
@commands.has_permissions(manage_roles = True)
async def dm(ctx, users: Greedy[User], *, message):
for user in users:
await user.send(message)
你直接私信@3422353423342 消息
@3422353423342代表一个用户id