当有人以不和谐的方式发送特定消息时,如何让 bot dm 我

How to make bot dm me when someone sends a specific message in discord

@client.event
async def on_message(message):
     if message.content == "help me":
         user = client.get(My_id) 
         if user is not None:
             await user.send("Someone needs help")

当有人发送特定文本时,有什么方法可以让 bot 私信我,比如他们在频道中键入 help me,我得到私信“嗨,有人需要帮助”我尝试了上面的代码,但没有成功,它显示 用户 = client.get(My_id) AttributeError: 'Bot' 对象没有属性 'get' 请在 python 中给出答案,在此先感谢您的回答,我正在为 discord

制作机器人

您可以使用 discord.py 库来实现 python。只需创建简单的事件侦听器并将 DM 发送给具有给定 ID 的用户,如下所示:

import discord

intents = discord.Intents.default()
intents.members = True

client = discord.Client()

@client.event
async def on_message(message):
    if message.content == "help me":
        user = client.get(YOUR_ID)  # specify your Discord account ID here
        if user is not None:
            await user.send("Hi someone needs help")

client.run("TOKEN")

试一试:

@client.event
async def on_message(message):
     if message.content == "help me":
         user = await client.fetch_user(12345678909876543) # id goes here

         if user is not None: # if id is correct
             if user.dm_channel is None: 
                 # if DM channel is not created
                 await user.create_dm()

             await user.dm_channel.send("Someone needs help")