Harjot
Harjot

Reputation: 943

on_guild_role_create event wont work in discord.py-rewrite v1.3.4

this is my code -

@client.event
async def on_guild_role_create(role):
    await asyncio.sleep(10)
    channel = client.get_channel(724859369732177953)
    guild = client.get_guild(690494216572239922)
    embed = discord.Embed(title=f"{guild.name}", description=f"**New Role Created - {role.mention}**", color=0x40cc88, timestamp=role.created_at)
    embed.set_thumbnail(url=guild.icon_url)
    embed.set_footer(text=f"{guild.name}")
    await channel.send(embed=embed)

and the above code shows the following error -

AttributeError: 'NoneType' object has no attribute 'name'

Any help will be much appreciated.

Upvotes: 0

Views: 224

Answers (1)

Pigeon Bread
Pigeon Bread

Reputation: 119

Couldn't you use discord.Guild.name instead?

This should return the name of the guild as a string

@client.event
async def on_guild_role_create(role):
    await asyncio.sleep(10)
    channel = client.get_channel(724859369732177953)
    guild = discord.Guild()
    embed = discord.Embed(title=f"{guild.name}", description=f"**New Role Created - {role.mention}**", color=0x40cc88, timestamp=role.created_at)
    embed.set_thumbnail(url=guild.icon_url)
    embed.set_footer(text=f"{guild.name}")
    await channel.send(embed=embed)```

Upvotes: 1

Related Questions