首页 文章

说,send_message和send,不能在@bot事件中工作怎么办? discord.py

提问于
浏览
1

您好重读了discord.py上的所有文档,遗憾的是没有找到像聊天中的on_member_join事件这样简单的事情发送消息?

我使用非标准构造,这样的构造客户端= 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);

打印()正确输出到控制台,但不幸的是将它发送到不和谐的聊天不起作用(

我也尝试过:

  • bot.say(member.name);

  • bot.send_message(member.name)

  • bot.send(member.name)

但是一直发出错误“'Bot'对象没有属性'说'”

请告诉我我做错了什么?

1 回答

  • 0

    您正在使用的 discord.py 版本将更改您发送邮件的方式 .

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

    await bot.send_message(message.channel, "I am responding to your message")
    
    await bot.say("I am responding to your command")
    

    discord.py 1.0,"rewrite"分支,是最新的分支 . 它仍被认为是实验性的,但完全可以使用 . 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版本

相关问题