0

Can you help me why I keep getting this error? AttributeError: 'str' object has no attribute 'server'

@commands.has_role("customer")
async def email(ctx,count=None,bomb_email=None,*,message=None):
    if message.server is not None:
        await ctx.send("nope")
    else:
        x = int(count)
    if message.server is not None:
        await ctx.send("yes")
        
    else:
        await ctx.send("nope")
1
  • 1
    Because your function has been called with message parameter being string so in your function, message (which is string) trying to access server attribute. Str doesn't have that attribute so it gives error. Commented Mar 3, 2021 at 15:43

2 Answers 2

1

If you want to get command's called server you can change message.server with ctx.guild.

Sign up to request clarification or add additional context in comments.

Comments

0

The problem is, you're trying to access a attribute called server which is not present the the str class. What I think you want is the discord.Message object. And even if you do that, there is no attribute called server for the Message class as well. I think what you need is the guild attribute which returns a discord.Guild object or None.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.