AttributeError:“客户端”对象没有属性“ send_message”(DiscordBot python)

时间:2019-08-13 17:37:59

标签: python bots discord

我在python上安装了我的不和谐欢迎程序,这是错误消息:

on_member_join中的文件“ welcome-bot.py”,第27行         等待client.send_message(成员,newUserMessage)    AttributeError:“客户端”对象没有属性“ send_message”

import discord
import asyncio

client=discord.Client()

@client.event
async def on_ready():
    print('logged in as')
    print(client.user.name)
    print(client.user.id)
    print('-----')

newUserMessage = """
is
that
works?
"""

@client.event
async def on_member_join(member):
    print("Recognised that a member called " + member.name + " joined")
    await client.send_message(member, newUserMessage)
    print("Sent message to " + member.name)```

1 个答案:

答案 0 :(得分:0)

Client不包含名为send_message的函数,您可以在其中PM / DM用户。

相反,您可以从加入的成员那里获取dm_channel属性,并在该频道中发送消息:

joinedUserDM = member.dm_channel

if joinedUserDM is None:
    await member.create_dm()
    joinedUserDM = member.dm_channel

joinedUserDM.send("message to send to the joined user's private inbox")