响应命令discord.py

时间:2019-06-08 23:59:58

标签: python discord.py

我制造了一个机器人,当有人用命令向他询问某事时,它应该响应,但不起作用。 它说这是一个属性错误,并且“ Client”类没有属性“ send_message”。

infos\main.py 
Logged in as
Beylogger
584809202523045889
------
['Type: Défense\n', 'Coup Spécial: ???\n', 'Utilité: Défense et endurance\n', 'Blader: Wakiya Murasaki\n', 'Disque: Armed\n', 'Pointe: Massive\n', 'Évolutions: Wild, Tornado\n', 'Date de sortie: 19 septembre 2015\n', 'Globalement: Excellente toupie pour sa génération']
Ignoring exception in on_message
Traceback (most recent call last):
  File "C:\Users\waabe\AppData\Local\Programs\Python\Python36-32\lib\site-packages\discord\client.py", line 251, in _run_event
    await coro(*args, **kwargs)
  File "C:\Users\waabe\AppData\Local\Programs\Python\Python36-32\beycommunity\infos\main.py", line 22, in on_message
    await discord.Client().send_message(message.channel, dex.format(author))
AttributeError: 'Client' object has no attribute 'send_message'
import discord
import sys
import os

TOKEN = 'I will not show it'

client = discord.Client()

@client.event
async def on_message(message):
    # we do not want the bot to reply to itself
    if message.author == client.user:
        return

    if message.content.startswith('bey!'):
        channel = client.get_channel("ID")
        message_real=(message.content).split("!")
        bey_name=message_real[1]
        where=bey_name+".txt"
        dex=open(where,"r").readlines()
        print(dex)
        await discord.Client().send_message(message.channel, dex.format(author))

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

client.run(TOKEN)

1 个答案:

答案 0 :(得分:0)

您需要使用TextChannel对象上调用的send

await message.channel.send("Some text")