3
import discord
import random
import asyncio
import pickle
import os


client = discord.Client()

@client.event
async def on_ready():
 print('logged in as')
 print(client.user.name)
 print(client.user.id)
 print('------')

@client.event
async def on_message(message):
 if message.content.startswith('!hello'):
    await client.send_message(message.channel,'sample text')

client.run(MY_TOKEN)

when i run it it prints the following message :

Traceback (most recent call last):
  File "C:/Users/Tommy/PycharmProjects/discord/discord.py", line 1, in <module>
    import discord
  File "C:\Users\Tommy\PycharmProjects\discord\discord.py", line 8, in <module>
client = discord.Client()
AttributeError: module 'discord' has no attribute 'Client'

not sure what to do here, i already set the paths in the interpreter but it still prints this message, i got all this code from a youtube video and it is verbatim so i dont know why it is not working

François M.
  • 4,027
  • 11
  • 30
  • 81
Tommy C
  • 31
  • 2
  • 1
    Did you, by chance, name a file `discord.py` ? -- Edit: actually, that's exactly what you did. You need to rename your file `discord.py` to something else. It's conflicting with the installed package. – sytech Jan 13 '18 at 02:08
  • 1
    @sytech He did, see the traceback. Flag for dupe? – internet_user Jan 13 '18 at 02:09

1 Answers1

1

Don't give your files the same name as the modules you are importing.

You are having this problem because your filename is "discord.py". Just change it and the code should work.

Also, you should avoid posting your token...

grovina
  • 2,999
  • 19
  • 25