AttributeError: 'User' object has no attribute 'guild_permissions' - discord.py

enter image description here
Hi Hello I have a question, why did I actually get this error I want to know what he actually says and I would love to get a detailed explanation.

Firstly, please provide atleast some code for context. Secondly, don't post a screenshot of the error, just include it as a codeblock in your post. That being said, my best guess from the limited information is that you need to use ctx.message.author. In your error screenshot, it seems you are just using message.author.

The guild_permissions.administrator is not exists on discord.py and that's why you getting "User" object has no attribute 'guild_permissions' error and you do not need to post a screenshot here but it's okay.
Also do you have the has_permissions?
If you do not have then
from discord.ext import commands, tasks
from discord.ext.commands import is_owner, has_permissions, MissingPermissions, BadArgument
If you do, use
#client.command()
#has_permissions(administrator=True)
async def command(ctx):
#yourscript
That's just my opinion what i was thinking.
If you're using on_message then please provide a script what you did.

Related

How would i create a private text channel using discord.py?

I want to make it so when a member says: !contact, it opens a private text channel that only the creator can see, as well as the admins. I am very new to discord.py so sorry if this seems like a basic question. Ik there are other questions like this, but none of them seem to work, they say "guild is not defined"
Edit: sorry for not providing code
When posting questions on StackOverflow, you should always try to give examples of what code you have been trying and what you're confused over. Our purpose by answering your questions is to give you a better understanding of a topic and to make sure that you understand what you did wrong, and how to improve.
To get an instance of the current guild that the command is being run in, you can utilize the command context's guild property. Once we have an instance of the guild, we can create a text channel and specify permissions that we want the channel to have. When specifying the channel overwrites, you use a dictionary to map either a role or member to permission overwrite.
import discord
#client.command()
async def contact(ctx):
guild = ctx.guild
admin_role = guild.get_role(0) # Replace with id of admin role
overwrites = {
guild.default_role: discord.PermissionOverwrite(view_channel=False),
ctx.author: discord.PermissionOverwrite(view_channel=True),
admin_role: discord.PermissionOverwrite(view_channel=True),
guild.me: discord.PermissionOverwrite(view_channel=True)
}
await guild.create_text_channel("private-channel", overwrites=overwrites) # Replace with name of text channel

I am trying to make a Telegram Bot. But getting error, don't know how to get rid of it

thats a simple code and Cmd output line
bot name - #ting_ting_bot
Ok, instead of telebot.Telebot use telebot.TeleBot. Note that B in TeleBot.
In the docs of pyTelegramBotApi's docs it is provided:
import telebot
bot = telebot.TeleBot("TOKEN", parse_mode=None) # You can set parse_mode by default. HTML or MARKDOWN

Problems with the bot discord Moderation

I created a lot of moderation teams, ban, kick muta, etc. I tried to do such a thing: If a person enters a command (for example, ban) and does not enter arguments (participant name and reason), the bot gives the corresponding message that there are not enough arguments and which one. Please help!
MissingRequiredArgument is called whenever a parameter that is required, is not encountered. You can use this exception to send a message in chat whenever a required argument is missing.
MissingRequiredArgument also has a parameter of its own, which details the argument that is missing.
Hope this points you in the right direction!
That's simple to implement. Here is the snippet of code to give you an idea.
async def test(ctx,name = None,reason = None):
if name == None or reason == None:
await ctx.send('Provide the Name and Reason')
else:
#PROCEEED HERE
pass

Discord.py how to check if the widget is disabled

I'm trying to check if the widget is enabled to avoid HTTP errors(404). But I can't find a way, even looking on the API reference. Can you please help me? Thank you.
Discord rewrite does not have an option to check if a widget  is online. In order to check this is eventually checking if you can get a valid response. Thus in order to still be able to check you need to try something with the widget to check if it is online.
Whenever you get a HTTP error you know it is offline (or not able to operate).
What I suggest is create a simple function to check if it is online:
# Checks if the widget is online by
# trying to access the widget through a guild object.
async def widget_is_online(guild):
try:
# or a function that needs online functionality
await guild.widget()
return True
except:
return False
Something that is also a good idea. Is to use a try-except at the place you try to use the widget. Where the except catches an http error exception. This is probably better and faster than using a function described earlier, to prevent http errors.
While I would generally advise against using except without a specific error, it ignores the exception when using urllibs HTTPError. If the Widget is disabled you should get a Forbidden: 403 Error though, not 404.
Since you haven't provided any code or example I've just written a small command that returns if the widget for the guild is available.
#bot.command()
async def check_widget(ctx):
try:
widget = await ctx.guild.widget()
ctx.send("Widget Available!")
except:
await ctx.send("Widget unavailable!")

SonarJs still shows warning about postMessage cross-domain issue

The error message is "make sure this cross-domain message is being sent to the intended domain".
This check rule from RSPEC-2819
Authors should not use the wildcard keyword ( *) in the targetOrigin argument in messages that contain any confidential information, as otherwise there is no way to guarantee that the message is only delivered to the recipient to which it was intended.
I assume it demands * cannot be used as targetOrigin, But It still shows warning when I use intended domain as targetOrigin like below:
Please somebody can tell me how to pass this check,
Any help would be appreciated
This rule detects only if a method postMessage is invoked on an object with a name containing window in it. Source code: PostMessageCheck.java. To bypass it, just assign your contentWindow object into different one, like this:
var content = this.elem.contentWindow;
content.postMessage('your message', window.location.origin);
Have faced similar issue in sonarQube. Below fix worked. Just get rid of using window object using directly.
Actual code:
window.parent.postMessage("data", parenturl);
Fix:
var content=window;
content.parent.postMessage("data",parenturl);

Resources