说,send_message和send,在@bot事件中不起作用怎么办?不和谐

时间:2018-06-23 04:36:23

标签: python discord discord.py

您好,您重新阅读了discord.py上的所有文档,但是不幸的是,在聊天中没有找到像 on_member_join 事件这样的简单消息来发送消息吗?

我使用的是非标准构造,这种构造为client = discord.Client(),但据我了解,新的 bot = commands.Bot(command_prefix ='!')

import discord
from discord.ext import commands

bot = commands.Bot(command_prefix='!')

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

@bot.event
async def on_member_join(member):
   print(member.name)   
   bot.send(member.name);

将()输出正确打印到控制台,但不幸的是,将其发送到不和谐的聊天室中(

我也尝试过:

  1. bot.say(member.name);
  2. bot.send_message(member.name)
  3. bot.send(member.name)

但是始终会发出错误消息“'Bot'对象没有属性'say''

请告诉我我做错了什么事

1 个答案:

答案 0 :(得分:0)

您使用的discord.py的版本将改变您发送消息的方式。

discord.py 0.16(“异步”分支)是当前的稳定版本。它有两种发送消息的方式。 (在下面,请注意BotClient的子类,因此每个Bot也可以访问所有Client方法)

  1. 使用Client.send_message(target, message)。这就是你 将在on_message(message)

    中使用
    await bot.send_message(message.channel, "I am responding to your message")     
    
  2. 使用Bot.say(message)。这是一种简单的发送方式     消息返回到在其中调用命令的通道。It only works in commands.

    await bot.say("I am responding to your command")
    

discord.py 1.0是“重写”分支,是最新的分支。仍被认为是实验性的,但完全可用。 One of the many changes is the way that message sending works.

现在,我们没有在客户端上使用发送消息的方法,而是在接收消息的事物上使用了向其发送消息的方法。这些都实现了Messageable抽象基类,并具有send方法。在您的on_message中,这看起来像

await message.channel.send("I am responding to your message")

我相信您正在使用1.0版