I'm making a discord bot using the Discord-py API and I've ran into a problem I cant get move member to work.
#bot.command(pass_context=True)
async def w(member = discord.Member):
await bot.say("Password Correct!")
await move_member(member, 5)
I'm getting this error
Ignoring exception in command w
Traceback (most recent call last):
File "C:\Program Files (x86)\Python36-32\lib\site-packages\discord\ext\commands\core.py", line 50, in wrapped
ret = yield from coro(*args, **kwargs)
File "C:\Users\Richard\Desktop\Test Bot\testbot2.py", line 29, in w
await move_member(member, 5)
NameError: name 'move_member' is not defined
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:\Program Files (x86)\Python36-32\lib\site-packages\discord\ext\commands\bot.py", line 846, in process_commands
yield from command.invoke(ctx)
File "C:\Program Files (x86)\Python36-32\lib\site-packages\discord\ext\commands\core.py", line 374, in invoke
yield from injected(*ctx.args, **ctx.kwargs)
File "C:\Program Files (x86)\Python36-32\lib\site-packages\discord\ext\commands\core.py", line 54, in wrapped
raise CommandInvokeError(e) from e
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: NameError: name 'move_member' is not defined
Anyone have a example I can use? Or any suggestions.
You forgot to specify bot.move_member. You're also doing your arguments wrong. If you pass the context, then the first argument to your function will be a context object. The syntax for converters is argument: Converter. The signature should be async def w(ctx, member: discord.Member):. Additionally, the second argument to Client.move_member must be a Channel object.
#bot.command(pass_context=True)
async def move(ctx, member: discord.Member, channel: discord.Channel):
await bot.say("Password Correct!")
await bot.move_member(member, channel)
Related
So, I have been working on a cog that attaches to my main.py file. The cog holds a !enter command along with a !start (command) function and !stop (command) function, which enables & disables the enter command from being used. The enter command takes the usernames of those that do !enter and puts them into a text file. However, whenever I start the bot and do !enter, everything works fine and it records the entry. After doing !enter, I do !stop entry and it disables the command !enter. But when I do !start entry to re-enable the command and type !enter, I get the error:
raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: TypeError: command_name_error() missing 1 required positional argument: 'error'
(error also populates if I try to do !enter after disabling the command as well. But it's like it won't re-enable and it populates the above error when I do !enter.)
This error is driving me bonkers and I can't find out why it's populating.
My code is below.
# COG CLASS
class Entries(commands.Cog):
def __init__(self, client):
self.client = client
# START UP
#commands.Cog.listener()
async def on_ready(self):
print('Entry.py is connected.')
# ENTER COMMAND
#commands.command(name="entry", aliases=["enter","Enter","ENTER"])
#commands.cooldown(1, 180, commands.BucketType.user)
async def entry(self, ctx):
filename = "entries.txt"
with open(filename, "a") as file:
file.write(f"{ctx.author.name}\n")
await ctx.send(f"**#{ctx.author.name} Your entry has been recorded. :white_check_mark:**")
#entry.error
async def command_name_error(self, ctx, error):
if isinstance(error, commands.CommandOnCooldown):
await ctx.send(f"**#{ctx.author.name} You have already entered! :warning:**")
# STOP COMMAND
#commands.command()
async def stop(self, ctx, *, command):
command = self.client.get_command(command)
command.update(enabled=False)
await ctx.author.send(f" The command **!enter** has been **disabled**.")
await ctx.channel.purge(limit=1)
# START COMMAND
#commands.command()
async def start(self, ctx, *, command):
command = self.client.get_command(command)
command.update(enabled=True)
await ctx.author.send(f" The command **!enter** has been **enabled**.")
await ctx.channel.purge(limit=1)
def setup(client):
client.add_cog(Entries(client))
FULL ERROR CODE
Ignoring exception in on_message
Traceback (most recent call last):
File "C:\Users\Nitro\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\discord\ext\commands\bot.py", line 939, in invoke
await ctx.command.invoke(ctx)
File "C:\Users\Nitro\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\discord\ext\commands\core.py", line 855, in invoke
await self.prepare(ctx)
File "C:\Users\Nitro\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\discord\ext\commands\core.py", line 789, in prepare
await self._parse_arguments(ctx)
File "C:\Users\Nitro\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\discord\ext\commands\core.py", line 697, in _parse_arguments
transformed = await self.transform(ctx, param)
File "C:\Users\Nitro\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\discord\ext\commands\core.py", line 542, in transform
raise MissingRequiredArgument(param)
discord.ext.commands.errors.MissingRequiredArgument: ctx is a required argument that is missing.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\Nitro\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\discord\ext\commands\core.py", line 71, in wrapped
ret = await coro(*args, **kwargs)
TypeError: command_name_error() missing 1 required positional argument: 'error'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:\Users\Nitro\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\discord\client.py",
line 343, in _run_event
await coro(*args, **kwargs)
File "C:\Users\Nitro\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\discord\ext\commands\bot.py", line 979, in on_message
await self.process_commands(message)
File "C:\Users\Nitro\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\discord\ext\commands\bot.py", line 976, in process_commands
await self.invoke(ctx)
File "C:\Users\Nitro\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\discord\ext\commands\bot.py", line 943, in invoke
await ctx.command.dispatch_error(ctx, exc)
File "C:\Users\Nitro\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\discord\ext\commands\core.py", line 424, in dispatch_error
await injected(ctx, error)
File "C:\Users\Nitro\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\discord\ext\commands\core.py", line 77, in wrapped
raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: TypeError: command_name_error() missing 1 required positional argument: 'error'
#bot.command()
async def createemoji(ctx):
with open('Racoon.jpg', 'rb') as f:
data = f.read()
await discord.Guild.create_custom_emoji(name='Raccoon', image=data)
This is the code, the image file is in the directory of the main.py.
This is the full error:
Ignoring exception in command createemoji:
Traceback (most recent call last):
File "C:\Users\imnap\Interpreter\lib\site-packages\discord\ext\commands\core.py", line 85,
in wrapped
ret = await coro(*args, **kwargs)
File "C:\Users\imnap\PycharmProjects\Cyrene\main.py", line 235, in createemoji
await discord.Guild.create_custom_emoji(name='Raccoon', image=data)
TypeError: create_custom_emoji() missing 1 required positional argument: 'self'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:\Users\imnap\Interpreter\lib\site-packages\discord\ext\commands\bot.py", line 939,
in invoke
await ctx.command.invoke(ctx)
File "C:\Users\imnap\Interpreter\lib\site-packages\discord\ext\commands\core.py", line 863,
in invoke
await injected(*ctx.args, **ctx.kwargs)
File "C:\Users\imnap\Interpreter\lib\site-packages\discord\ext\commands\core.py", line 94,
in wrapped
raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: TypeError:
create_custom_emoji() missing 1 required positional argument: 'self'
I've looked up dozens of posts very similar to mine, but most of them aren't to do with discord.py. I've looked up the documention and it should be formatted exactly as needed. Sorry if this is a stupid question, but I'm at a loss as to the issue.
You try to create the emoji to the class discord.Guild
What you realy want to do, is to add the emote to the guild the command is used in
#bot.command()
async def createemoji(ctx):
guild = ctx.guild
with open('Racoon.jpg', 'rb') as f:
data = f.read()
await guild.create_custom_emoji(name='Raccoon', image=data)
my current code is
#client.command()
async def check_vouches(ctx, member : discord.User=None):
users = await get_vouch_data()
test = ctx.author
role = discord.utils.get(test.guild.roles, name="10 vouches")
vouches_gotten = users[str(member.id)]["vouches_gotten"]
if member is not None:
if vouches_gotten == 10:
await test.add_roles(role)
await ctx.send("you now have the {role} role")
else:
await ctx.reply("first get 10 vouches")
which does not give an error code when i start the bot but when i try use the command i get the following error code:
Ignoring exception in command check_vouches:
Traceback (most recent call last):
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/core.py", line 85, in wrapped
ret = await coro(*args, **kwargs)
File "main.py", line 193, in check_vouches
vouches_gotten = users[str(member.id)]["vouches_gotten"]
AttributeError: 'NoneType' object has no attribute 'id'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/bot.py", line 939, in invoke
await ctx.command.invoke(ctx)
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/core.py", line 863, in invoke
await injected(*ctx.args, **ctx.kwargs)
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/core.py", line 94, in wrapped
raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: AttributeError: 'NoneType' object has no attribute 'id'
i have already tried putting
async def check_vouches(ctx, member : discord.User=None,*, id):
but when i tried even with an id there it still didn't work. please help me as i am out of ideas as i have tried editing several things and it still gave me an error code
As said in the comments, you are only proceeding when the member is None, which shouldn't be the case.
If the member is None, you can do two things, give it a default value and proceed or stop the command and raise an error.
Stopping the command:
if member is None:
await ctx.send('You have to mention someone to check their vouches')
else:
# check and show vouch
Providing a default value: (author)
if member is None:
member = ctx.author
# don't check if member is None later
#check and show vouches
I'm making a bot for my Discord server using discord.py . I'm trying to make a command that gives a user a role named "Muted". But when I try and mute the user (by sending "0mute #user#0000"), I get errors.
My code for giving the role is this:
#client.command(pass_context=True)
#commands.has_any_role("Admin")
async def mute(ctx, user: discord.Member):
await user.add_roles("Muted", atomic=False)
Note: I'm using regular discord.py, NOT discord.py rewrite.
Edit:
Recently found out I'm not allowed to post images of errors or code, as such I'll past the errors here as text instead of an image.
Ignoring exception in command mute:
Traceback (most recent call last):
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/core.py", line 85, in wrapped
ret = await coro(*args, **kwargs)
File "main.py", line 43, in mute
await user.add_roles("Muted", atomic=False)
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/member.py", line 669, in add_roles
new_roles = utils._unique(Object(id=r.id) for s in (self.roles[1:], roles) for r in s)
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/utils.py", line 287, in _unique
return [x for x in iterable if not (x in seen or adder(x))]
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/utils.py", line 287, in <listcomp>
return [x for x in iterable if not (x in seen or adder(x))]
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/member.py", line 669, in <genexpr>
new_roles = utils._unique(Object(id=r.id) for s in (self.roles[1:], roles) for r in s)
AttributeError: 'str' object has no attribute 'id'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/bot.py", line 902, in invoke
await ctx.command.invoke(ctx)
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/core.py", line 864, in invoke
await injected(*ctx.args, **ctx.kwargs)
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/core.py", line 94, in wrapped
raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: AttributeError: 'str' object has no attribute 'id'
Member.add_roles takes discord.Role instances as the arguments, you're passing a string.
#client.command()
#commands.has_any_role("Admin")
async def mute(ctx, user: discord.Member):
role = discord.utils.get(ctx.guild.roles, name="Muted") # Getting the role
await user.add_roles(role, atomic=False)
Also the pass_context kwarg is not necessary in discord.py rewrite, the context is always passed
Reference:
utils.get
Member.add_roles
I want to change permissions of all channels of a server from Read messages = True to False. Basically I don't want users with default-role to be able to see any of the channel.
What I wrote:
#bot.command()
async def maintainance(ctx):
channel = ctx.guild.channels
perms = channel.overwrites_for(ctx.guild.default_role)
perms.read_messages=False
for channel in ctx.guild.channels:
await channel.set_permissions(ctx.guild.default_role, overwrite=perms)
await ctx.message.add_reaction(emoji="<a:tick:748476262640779276>")
error I get:
Ignoring exception in command maintainance:
Traceback (most recent call last):
File "C:\Users\Rohit\AppData\Roaming\Python\Python37\site-packages\discord\ext\commands\core.py", line 83, in wrapped
ret = await coro(*args, **kwargs)
File "c:\Users\Rohit\Desktop\discord bots\tutorial bot\bot.py", line 23, in maintainance
perms = channel.overwrites_for(ctx.guild.default_role)
AttributeError: 'list' object has no attribute 'overwrites_for'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:\Users\Rohit\AppData\Roaming\Python\Python37\site-packages\discord\ext\commands\bot.py", line 892, in invoke
await ctx.command.invoke(ctx)
File "C:\Users\Rohit\AppData\Roaming\Python\Python37\site-packages\discord\ext\commands\core.py", line 797, in invoke
await injected(*ctx.args, **ctx.kwargs)
File "C:\Users\Rohit\AppData\Roaming\Python\Python37\site-packages\discord\ext\commands\core.py", line 92, in wrapped
raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: AttributeError: 'list' object has no attribute 'overwrites_for'
I don't know what I did wrong.
Overwrites are per channel so you need to do the get_overwrites inside the for loop, some psuedocode would look like
for every channel:
overwrites = get_overwrites()
overwrites.send_message = False
channel.set_permissions(default_role, overwrites=overwrites)
Another thing is that you should do ctx.message.add_reaction() outside the loop to avoid trying to add the same reaction multiple times