Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

discord - Problems with a serverinfo command

n = [role.mention for role in ctx.guild.roles]
        u = n[len(n) - 1]
        ab = n[0]

Above, the variable n is supposed to create a list of roles in the server which it does, and the variable u is used to get a Server's highest positioned role which it does too.

the variable ab, however in any case should return @everyone but it returns @@everyone any way I can fix this? or somehow replace @@everyone with @everyone

I tried the following:
ab = n[0]
if ab == f"@<@{ctx.guild.default_role.id}>":
           ab = f"<@{ctx.guild.default_role.id}>"

however, it didn't work. Any help would be appreciated enter image description here

enter image description here

question from:https://stackoverflow.com/questions/65856691/problems-with-a-serverinfo-command

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

This happens because the default name of the role is already "@everyone", so when you retrieve the mention it adds another "@" to it, becoming @@everyone". What you could do to solve this would be replacing this with "everyone" like this:

    n = [role.mention for role in ctx.guild.roles[1:]]  # Ignore the @everyone
    n.insert(0,'@everyone')  # Add string @everyone at the beginning
    # Here goes the rest of your code

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...