【问题标题】:Respond to a command discord.py [duplicate]响应命令 discord.py [重复]
【发布时间】:2019-10-23 22:41:07
【问题描述】:

我制作了一个机器人,当有人用命令问他某事时,它应该会响应,但它不起作用。 它说它是一个属性错误,并且“客户端”类没有属性“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)

【问题讨论】:

    标签: python discord.py


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-02-10
      • 2020-09-12
      • 1970-01-01
      • 1970-01-01
      • 2021-04-09
      • 2021-10-06
      • 1970-01-01
      相关资源
      最近更新 更多