不知道为什么bot.send_message不起作用

时间:2018-10-05 07:21:38

标签: python discord discord.py

我遇到一个我不明白的问题。这是我的代码:

@bot.event
async def on_member_join(member):
    print (member, " joined")
    embed = discord.Embed(title="{} just joined the server!".format(member.name), description="Welcome!", color=0x00ff00)
    #await bot.say(embed=embed) // can't use this outside a command
    await bot.send_message(message.channel, embed=embed) # New - 4 Oct

错误:

File "/Users/marco/Desktop/spambot/bot.py", line 23, in on_member_join
    await bot.send_message(message.channel, embed=embed) # New - 4 Oct
NameError: name 'message' is not defined

有人知道我在做什么错吗?

1 个答案:

答案 0 :(得分:0)

您尚未在代码中的任何地方定义message
您需要指定发送消息的通道,方法是使用get_channel(channel_id)获取消息,或者循环遍历member.server.channels并选择具有所需属性的消息

@bot.event
async def on_member_join(member):
    print (member, " joined")
    embed = discord.Embed(title="{} just joined the server!".format(member.name), description="Welcome!", color=0x00ff00)
    #await bot.say(embed=embed) // can't use this outside a command
    await bot.send_message(bot.get_channel("YOUR_CHANNEL_ID"), embed=embed) # New - 4 Oct