我只想通过 python 代码向我的朋友发送 DM。
这是我的代码,但它不起作用。
代码:
import discord
client = discord.Client(token="MY_TOKEN")
async def sendDm():
user = client.get_user("USER_ID")
await user.send("Hello there!")
我只想通过 python 代码向我的朋友发送 DM。
这是我的代码,但它不起作用。
代码:
import discord
client = discord.Client(token="MY_TOKEN")
async def sendDm():
user = client.get_user("USER_ID")
await user.send("Hello there!")
fetch_user
代替get_user
(fetch
请求 Discord API 而不是其内部缓存):async def sendDm():
user = await client.fetch_user("USER_ID")
await user.send("Hello there!")
on_ready
event运行它:@client.event
async def on_ready():
user = await client.fetch_user("USER_ID")
await user.send("Hello there!")
import discord
client = discord.Client()
@client.event
async def on_ready():
user = await client.fetch_user("USER_ID")
await user.send("Hello there!")
client.run("MY_TOKEN")
那么您是否尝试使用命令执行此操作?如果是这样的话
@bot.command()
async def dm(ctx, user: discord.User = None, *, value = None):
if user == ctx.message.author:
await ctx.send("You can't DM yourself goofy")
else:
await ctx.message.delete()
if user == None:
await ctx.send(f'**{ctx.message.author},** Please mention somebody to DM.')
else:
if value == None:
await ctx.send(f'**{ctx.message.author},** Please send a message to DM.')
else:
` await user.send(value)