“客户端”对象没有属性“ send_message”

时间:2018-10-02 16:36:30

标签: python python-3.x discord discord.py

运行在控制台上产生此错误时,您可以修复它吗?我自己不太了解,所以需要您的帮助。

import feedparser
import discord
import asyncio

url = 'http://blog.counter-strike.net/index.php/feed/'

Client = discord.Client()
global last_id
last_id = []

#---Edit this before running the bot------
#1] Add the App Bot User Token you got from discord here
token = ...
#2] Add the Discord Channel IDs to which the bot will message when CSGO updates .
#bot has to be a part of the group to which the channel belongs . duh
channel_id = ['496709417203662848', '496709455816294411', '496709586196365323']

async def print_console(text):
    await Client.wait_until_ready()
    print(text)
    for num in channel_id:
        await Client.send_message(Client.get_channel(num),text)

@Client.event
async def on_ready():
    await Client.change_presence(game=discord.Game(name='CSGO-Updates'))
    print('Logged in as')
    print(Client.user.name)
    print(Client.user.id)
    print('------')

@Client.event
async def on_message(message):
    if message.content.startswith('!check'):
        await Client.send_message(message.channel,'bot Running')
    if message.content.startswith('!help'):
        help_msg = '***the currently active commands are:***\n ```css\n{}\n``` \n'
        text = ' !help : displays the help documentation\n !check : checks if the bot is running,returns 0 or no message if bot is having problems\n !madeby : Steam URL of the bot Creator \n '
        await Client.send_message(message.channel, help_msg.format(text))
    if message.content.startswith('!madeby'):
        msg = ' *made by:* \n http://steamcommunity.com/id/zero_aak'
        await Client.send_message(message.channel, msg)

async def main():
    global last_id
    feed = feedparser.parse(url)
    for index in feed.entries:
        last_id.append(index.id)
    print('primary scan complete')
    await print_console('bot started , use !help for help')
    while True:
        await asyncio.sleep(20)
        feed = feedparser.parse(url)
        for item in feed.entries:
            if item.id not in last_id:
                last_id.append(item.id)
                await print_console(item.link)

Client.loop.create_task(main())
Client.run(token)

这是控制台中显示的内容

C:\Users\FeNka\Downloads\Discord-CSGO-Update-bot-master\Discord-CSGO-Update-bot-master>python bot.py primary scan complete bot started , use !help for help Task exception was never retrieved future: <Task finished coro=<main() done, defined at bot.py:44> exception=AttributeError("'Client' object has no attribute 'send_message'")> Traceback (most recent call last): File "bot.py", line 50, in main await print_console('bot started , use !help for help') File "bot.py", line 22, in print_console await Client.send_message(Client.get_channel(num),text) AttributeError: 'Client' object has no attribute 'send_message' Ignoring exception in on_ready Traceback (most recent call last): File "C:\Users\FeNka\AppData\Local\Programs\Python\Python37-32\lib\site-packages\discord\client.py", line 225, in _run_event await coro(*args, **kwargs) File "bot.py", line 26, in on_ready await Client.change_presence(game=discord.Game(name='CSGO-Updates')) TypeError: change_presence() got an unexpected keyword argument 'game'

如果需要的话,这是运行指南))

让它自己运行: 1)如果您还没有Python,请安装它(推荐版本3.6+) 2)在此处创建一个不和谐的新应用 https://discordapp.com/developers/applications/me 3)将Bot用户添加到应用中,并保存令牌以供以后使用。 4)获取应用程序的客户端ID 5)使用此链接将漫游器添加到服务器,将URL中的CLIENT_ID替换为您获得的客户端ID: https://discordapp.com/oauth2/authorize?client_id=CLIENT_ID&scope=bot&permissions=0 6)在用户设置->外观->启用开发人员模式中启用开发人员模式 7)右键点击频道,获取频道ID,保存以备后用 8)在记事本中打开bot.py,然后在给定位置输入bot令牌和channel-id。 9)在python中执行bot.py。 10)在这里,您可以完成使用!help来查看机器人是否正在运行:)

命令:

!help:显示帮助对话框 !check:检查机器人是否正在运行 !madeby:获取我的Steam个人资料网址与我联系

2 个答案:

答案 0 :(得分:0)

您可能正在对discord.py进行重写。这样做:

import discord print(discord.__version__)

如果它带有1.0.0a,则将其重写,则0.16.0是异步的。

答案 1 :(得分:0)

为帮助您,我需要知道您使用的discord.py的版本。您可以尝试:

await client.change_presence(activity=discord.Game(name="CSGO-Updates"))

就做

import discord
print(discord.__version__)