I
I
Igor Gafarchik2020-05-12 20:56:00
Python
Igor Gafarchik, 2020-05-12 20:56:00

Discord.py bot Hello?

Hi all.
I'm writing a discord bot. I wrote an algorithm for greeting new users and then an error(

@bot.event
async def on_member_join(member):
    server = member.server
    channel = server.default_channel
    retStr = str("""```yaml\nПривет!\nДобро пожаловать на наш сервер!\nНадеюсь тебе тут понравится.\nЕсли заблудешься пиши !help,кстати у нас все команды пишутся с !\nДля получения роли зайди в чат получения роли\nудачи тебе```""")
    embed = discord.Embed(title="Welcome",colour=discord.Colour.blue())
    embed.add_field(name="Привет",value=retStr)
    await bot.send_message(channel, embed=embed)

Got into the forums first. There are many solutions. And everywhere there is one mistake (
Ignoring exception in on_member_join
Traceback (most recent call last):
  File "C:\Users\gafig.DESKTOP-B4N254S\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\discord\client.py", line 312, in _run_event
    await coro(*args, **kwargs)
  File "B:\discordbot\role.py", line 47, in on_member_join
    server = member.server
AttributeError: 'Member' object has no attribute 'server'

Who can prompt or at least suggest an idea?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Deleting Account, 2020-05-13
@Gafarchik

The server in discord.py is guild, not server, read the error - it says that member does not have a server attribute. Use member.guild! https://discordpy.readthedocs.io/en/latest/api.htm...

M
MisterVladik, 2021-11-03
@MisterVladik

@client.event
async def on_member_join(member):
server = member.server
channel = server.default_channel
retStr = str("""```yaml\nHello!\nWelcome to our server!\nHope you enjoy it here.\nIf if you get lost, write !help, by the way, all our commands are written with !\nTo get a role, go to the chat for getting a role\ngood luck```""")
embed = discord.Embed(title="Welcome",colour=discord.Colour. blue())
embed.add_field(name="Hi",value=retStr)
no error here

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question