Discord.py - client.send_message()不发送消息 - Python 3.6

时间:2017-12-17 11:08:48

标签: python-3.x discord.py

client = discord.Client()
noticeme = 'notice me senpai'

@bot.event
async def on_message(message):
    author = message.author
    authorid = message.author.id
    print ("@{} user sent a message. (id: {})".format(author, authorid))

    if message.content == noticeme:
        print ('I noticed you @{}!'.format(authorid))
        await client.send_message(message.channel, 'I noticed you @{}!'.format(authorid))

我正在尝试制作一个响应“我注意到你@username!”的命令当你说“注意我senpai”但它不起作用。 (印刷品工作)

3 个答案:

答案 0 :(得分:1)

client = discord.Client()
noticeme = 'notice me senpai'

@client.event
async def on_message(message):
    author = message.author
    authorid = message.author.id
    print ("@{} user sent a message. (id: {})".format(author, authorid))

    if message.content == noticeme:
        print ('I noticed you @{}!'.format(authorid))
        await client.send_message(message.channel, 'I noticed you @{}!'.format(author))

这应该是你的代码。 您使用的@bot.event应由@client.event替换。 我测试了您的代码,如果您想使用@提及,则需要使用author变量而不是authorid变量。

希望这有帮助。

答案 1 :(得分:0)

您正在使用await client.send_message()而不是await bot.send_message()

答案 2 :(得分:0)

也许不是await client.send_message(message.channel, 'I noticed you @{}!'.format(author)),而是尝试await message.send('I noticed you @{}!'.format(author))