Rapptz / discord.py

An API wrapper for Discord written in Python.
http://discordpy.rtfd.org/en/latest
MIT License
14.71k stars 3.74k forks source link

"Channel" object has no attribute "send" #1773

Closed TrackLab closed 5 years ago

TrackLab commented 5 years ago

Following this Tutorial https://pythonprogramming.net/discordpy-basic-bot-tutorial-introduction/ I created a discord bot, but the send method does not work. While it works for the person in the tutorial, and we use the same version.

client = discord.Client()
#channel = client.get_channel("513716202355425290"

@client.event
async def on_message(message):
    print(f"{message.channel}: {message.author}: {message.author.name}: {message.content}")

    if "hi there" in message.content.lower():
        await message.channel.send("Hi!")

This simply returns the error that the method send does not exist.

crrapi commented 5 years ago

It appears you do not have the rewrite version of the library to go with your rewrite code. To get help installing it, you should join either the official discord.py server or the Discord API server for help, as the README recommends.

Gorialis commented 5 years ago

This tutorial is third-party. It's recommended that you learn through the documentation and examples as most online tutorials prove themselves to be either incomplete, out of date or of poor quality.

The presented does not work because this code is written for compatibility with the rewrite (v1.0) branch and not the async (v0.16) branch. This is actually mentioned in the tutorial you linked.

Either switch to rewrite, or write async code instead.

TrackLab commented 5 years ago

It appears you do not have the rewrite version of the library to go with your rewrite code. To get help installing it, you should join either the official discord.py server or the Discord API server for help, as the README recommends.

I joined the Discord server, everytime I try to go on it my discord crashes and restarts. So that does not work.

Also where would I get the rewrite version? I downloaded this github version, just like in the tutorial, with the same code that got shown in the tutorial.

TrackLab commented 5 years ago

I found this https://stackoverflow.com/questions/50686388/how-to-install-discord-py-rewrite with the command pip install -U git+https://github.com/Rapptz/discord.py@rewrite#egg=discord.py[voice] which overwrite the discordpy installation with the rewrite. This:

@client.event
async def on_message(message):
    print(f"In Channel {message.channel}:\n{message.author.name} ({message.author}) wrote: {message.content}")

    if "hi there" in message.content.lower():
        await message.channel.send('hello')

Works now. Thanks