简体   繁体   English

如何向执行 discord 机器人命令的用户发送直接消息?

[英]How can i send a direct message to a user that executed a command to my discord bot?

So i want to make an minecraft account generator with a discord.py bot.所以我想用 discord.py 机器人制作一个我的世界帐户生成器。 I got almost everything to work but im struggling to make the bot direct message the person that wrote the command ("$minecraft nfa").我几乎完成了所有工作,但我努力让机器人直接向编写命令的人发送消息(“$ minecraft nfa”)。

I want it so after the user inputs this command, he gets a direct message from my bot that sends him the account details.我想要它,所以在用户输入此命令后,他会从我的机器人那里收到一条直接消息,向他发送帐户详细信息。 Everything works except that part.除了那部分,一切都有效。 Here is my code:这是我的代码:

   if message.content.startswith("$minecraft nfa"):
        author = message.author
        minecraft_nfa = open("minecraft_nfa.txt", "r")
        minecraft_nfa = minecraft_nfa.readlines()
        if message.author == client.user:
            return
        embed = Embed(
            description=('I send you the account {0.name}, check your dms!'.format(author)),
            color=0x5CDBF0,
        )
        embed.set_image(url="https://i.imgur.com/w5dtwgo.png")
        embed.set_footer("Accounts provided by y#9999, bot made by rarytud#9999 and y#9999")
        await message.channel.send(embed=embed)```

I get this Error:我得到这个错误:

Traceback (most recent call last):
  File "C:\Users\luka\AppData\Local\Programs\Python\Python38\lib\site-packages\discord\client.py", line 333, in _run_event
    await coro(*args, **kwargs)
  File "c:/Users/luka/OneDrive/Desktop/EVERYTHING/Private Sniper2/100 Param,/idk/random/PGSharp/Discord Gen Bot/main.py", line 92, in on_message
    await client.send_message(member, random.choice(minecraft_nfa))
AttributeError: 'Client' object has no attribute 'send_message'"```

So i want to make an minecraft account generator with a discord.py bot.所以我想用 discord.py 机器人制作一个我的世界帐户生成器。 I got almost everything to work but im struggling to make the bot direct message the person that wrote the command ("$minecraft nfa").我几乎完成了所有工作,但我努力让机器人直接向编写命令的人发送消息(“$ minecraft nfa”)。

I want it so after the user inputs this command, he gets a direct message from my bot that sends him the account details.我想要它,所以在用户输入此命令后,他会从我的机器人那里收到一条直接消息,向他发送帐户详细信息。 Everything works except that part.除了那部分,一切都有效。 Here is my code:这是我的代码:

   if message.content.startswith("$minecraft nfa"):
        author = message.author
        minecraft_nfa = open("minecraft_nfa.txt", "r")
        minecraft_nfa = minecraft_nfa.readlines()
        if message.author == client.user:
            return
        embed = Embed(
            description=('I send you the account {0.name}, check your dms!'.format(author)),
            color=0x5CDBF0,
        )
        embed.set_image(url="https://i.imgur.com/w5dtwgo.png")
        embed.set_footer("Accounts provided by y#9999, bot made by rarytud#9999 and y#9999")
        await message.channel.send(embed=embed)```

I get this Error:我得到这个错误:

Traceback (most recent call last):
  File "C:\Users\luka\AppData\Local\Programs\Python\Python38\lib\site-packages\discord\client.py", line 333, in _run_event
    await coro(*args, **kwargs)
  File "c:/Users/luka/OneDrive/Desktop/EVERYTHING/Private Sniper2/100 Param,/idk/random/PGSharp/Discord Gen Bot/main.py", line 92, in on_message
    await client.send_message(member, random.choice(minecraft_nfa))
AttributeError: 'Client' object has no attribute 'send_message'"```

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在 discord.py 中的某个时间间隔后向用户发送直接消息? - How can I send a direct message to a user after a certain interval in discord.py? 如何让我的 discord.py 机器人向我选择的频道发送我选择的消息? - how can i make my discord.py bot send a message i choose to a channel i choose? 我的不和谐机器人如何发送欢迎信息并提供角色 - How can my discord bot send a welcome message and give a role 我在 python 中按下反应后,如何让我的 discord 机器人发送消息? - How can i get my discord bot to send a message after i press a reaction in python? 如何通过单独的函数为 python 中的不和谐机器人发送消息? - How can I send a message through a separate function for my discord bot in python? 如何让我的 discord.py 机器人删除在特定频道上发送的每条消息? - How can I make my discord.py bot delete every message send on a specific channel? 如何让我的 Discord 机器人向服务器发送更干净的消息 - How Can I get My Discord Bot To Send A Cleaner Message To Server 如何使用 python discord 向机器人所在的每个服务器发送消息 - How can I send a message to every server the bot is in with python discord 如何让我的 Discord Bot 使用他们的用户 ID 向另一个用户发送私人消息,我尝试了以下操作,但没有成功 - How Do I get my Discord Bot to Send a private message to another user using their user ID,I tried the following but it did not work 如何让我的“说”命令删除命令消息,同时保留机器人的消息? (discord.py) - How can I make my “say” command delete the command message, while keeping the bot's message? (discord.py)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM