PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Sunday, July 10, 2022

[FIXED] How to get message author id in discord.py? - Discord Python

 July 10, 2022     author, discord, discord.py, message, python     No comments   

Issue

Problem is, if i try to use message.author.id, it will say

"Cannot find reference 'author' in 'message.py'

Basically what i want to do in the code bellow is: a command that only certain id's have access to and that they can use to give their role away to someone.

Thanks for any help!

@client.command(pass_context=True)
@commands.has(939236844137226290)
async def asteroid(ctx, user: discord.Member):
    if  message.author.id == 939236844137226290:
        role = ctx.guild.get_role(939236844137226290)
        await user.add_roles(role)
        await ctx.send(f"{user.name} has received {role} from {ctx.author.name}!")
    else:
        await ctx.send("Only asteroidblues has permission to give the role away")

Solution

The problem is probably that you imported discord.Message but you have to use message.author.id when message is a variable containing a discord.Message instance, which you don't have in this case. But what you do have is ctx, the context, from which you can access the author id by using ctx.author.id.



Answered By - Chuaat
Answer Checked By - Willingham (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing