我正在使用discord.py创建一个discord bot,当用户使用特定命令时,我希望创建一个特定用户
from discord import DMChannel
client = discord.Client()
client = commands.Bot(command_prefix=']')
@client.command(name='dmsend', pass_context=True)
async def dmsend(ctx, user_id):
user = await client.fetch_user("71123221123")
await DMChannel.send(user, "Put the message here")
当我发出命令dmsend时,什么也没有发生。我也试过了。但什么也没发生
我注意到了几件事:
您定义了
client
两次,这只会出错首先)删除
client = discord.Client()
,您不再需要它了如果要向特定用户ID发送消息,则不能将其括在引号中。另外,您应该小心使用
fetch
,因为这样会向API发送请求,并且它们受到限制Second)将
await client.fetch_user("71123221123")
更改为以下内容:如果您有希望消息转到的
user
,则不需要创建另一个DMChannel
Third)将
await DMChannel.send()
转换为以下内容:您可能还需要启用
members
意图,下面是一些关于这方面的好文章:打开Intents后的完整代码可以是:
使用
await user.send("message")
相关问题 更多 >
编程相关推荐