尝试制作不和谐的机器人,但为什么 client.send() 错误?

try make discord bot, but why client.send() error?

import discord
import requests
import asyncio
from json import loads

twitch_Client_ID = 'id'
twitch_Client_secret = 'secret'
discord_Token = 'token'
discord_channelID = 'id'
discord_bot_state = 'TEST'
twitchID = 'tid'
msg = 'LIVE! https://www.twitch.tv/' + twitchID

client = discord.Client()


@client.event
async def on_ready():
    print(client.user.id)
    print("ready")

    game = discord.Game(discord_bot_state)
    await client.change_presence(status=discord.Status.online, activity=game)

    channel = client.get_channel(int(discord_channelID))

    oauth_key = requests.post("https://id.twitch.tv/oauth2/token?client_id=" + twitch_Client_ID +
                              "&client_secret=" + twitch_Client_secret + "&grant_type=client_credentials")
    access_token = loads(oauth_key.text)["access_token"]
    token_type = 'Bearer '
    authorization = token_type + access_token
    print(authorization)

    check = False

    while True:
        print("ready on Notification")

        headers = {'client-id': twitch_Client_ID,
                   'Authorization': authorization}
        response_channel = requests.get(
            'https://api.twitch.tv/helix/streams?user_login=' + twitchID, headers=headers)
        print(response_channel.text)

        # try:
        if loads(response_channel.text)['data'][0]['type'] == 'live' and check == False:
            await client.wait_until_ready()
            await channel.send(msg)
            print("Online")
            check = True
        # except:
            # print("Offline")
            #check = False

        await asyncio.sleep(10)

client.run(discord_Token)

这是我所有的代码.. 和 我看到了这个错误

AttributeError: 'NoneType' 对象没有属性 'send'

        # try:
        if loads(response_channel.text)['data'][0]['type'] == 'live' and check == False:
            await client.wait_until_ready()
            await channel.send(msg)

我认为有问题的代码在这里。 这里出了什么问题? 为什么总是出错.....

我试试 这个:https://www.reddit.com/r/discordapp/comments/6ylp7t/python_bot_channel_object_has_no_attribute_send/ 还有这个: AttributeError: 'NoneType' object has no attribute 'send' Discord.py rewrite

但对我不起作用!

看起来像你的 channel is None。根据 docs get_channel(id: int) 可能 return None 找不到频道时。仔细检查您的 discord_channelID 是否正确并且它是 int(不是您示例中的 str)。