Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.9k views
in Technique[技术] by (71.8m points)

python - AttributeError: 'NoneType' object has no attribute 'send' discord bot

I need help getting my bot to work

# Import Discord Package
import discord

# Client (our bot)
client = discord.Client()

@client.event
async def on_ready():
    # DO STUFF....
    general_channel = client.get_channel()

    await general_channel.send('yo')

# Run the client on the server
client.run('')

when I run it i get AttributeError: 'NoneType' object has no attribute 'send' in terminal and nothing shows up on discord if you could fix it that would be great

question from:https://stackoverflow.com/questions/65839365/attributeerror-nonetype-object-has-no-attribute-send-discord-bot

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The common reasons why get_ would return None are: a) The channel ID is not found b) The bot is not connected c) get_ method is called before the bot is started.

In your case there are 2 obvious misses

  1. get_channel method requires a parameter which is the channel ID. https://discordpy.readthedocs.io/en/latest/api.html#discord.Guild.get_channel

  2. The bot is likely not loggedIn as client.run() also requires a token parameter. client.run('your_token')


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...