get_member_named() missing 1 required positional argument: 'name' - python

#my_bot.event
async def on_message(message):
if message.content.startswith('!test'):
server = discord.Server
await my_bot.send_message(server.get_member_named('mystery#5137'), 'Hello')
Why didn't work?
Error:
Ignoring exception in on_message
Traceback (most recent call last):
File "C:\Users\Roman-PC\AppData\Local\Programs\Python\Python36-32\lib\discord\client.py", line 307, in _run_event
yield from getattr(self, event)(*args, **kwargs)
File "C:/Users/Roman-PC/Desktop/t1.py", line 11, in on_message
await my_bot.send_message(server.get_member_named('name'), 'Hello')
TypeError: get_member_named() missing 1 required positional argument: 'name'

You shouldn't create a discord.Server, rather you should get the server from the message object as (see the docs for discord.Message)
s = message.server
then you can
s.get_member_named('mystery#5137')

You need to define the Member with a name.
Instead of putting:
server = discord.Server
await my_bot.send_message(server.get_member_named('mystery#5137'), 'Hello')
You need:
server = message.server
await my_bot.send_message(server.get_member_named(name='mystery#5137'), 'Hello')

Related

I'm trying to create an emoji out of an image with create_custom_emoji and I'm getting a 'issing 1 required positional argument: 'self''

#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)

on_raw_reaction_add(payload) troubleshooting

Hey i am developing a Discord Bot with Python.
Here is the documentation: https://discordpy.readthedocs.io/en/latest/index.html
This program should give a user a role if he or she reacts to a message
I tried to define the ctx in the function itself
#client.event
async def on_raw_reaction_add(payload):
member = discord.utils.get(client.get_all_members())
role = discord.utils.find(lambda r: r.name == "check-in", ctx.guild.roles)
check_in = ["612637944544624690"]
if str(payload.channel_id) in check_in:
await client.add_roles(member, role, reason="check-in")
That is the error without ctx in the function itself:
Ignoring exception in on_raw_reaction_add
Traceback (most recent call last):
File "C:\Users\kaitr\Anaconda3\envs\tutorial\lib\site-packages\discord\client.py", line 270, in _run_event
await coro(*args, **kwargs)
File "C:/Users/kaitr/PycharmProjects/Discord Tutorial/bot.py", line 39, in on_raw_reaction_add
role = discord.utils.find(lambda r: r.name == "check-in", ctx.guild.roles)
NameError: name 'ctx' is not defined
That is the error with ctx in the function itself:
Ignoring exception in on_raw_reaction_add
Traceback (most recent call last):
File "C:\Users\kaitr\Anaconda3\envs\tutorial\lib\site-packages\discord\client.py", line 270, in _run_event
await coro(*args, **kwargs)
TypeError: on_raw_reaction_add() missing 1 required positional argument: 'ctx'
You don't have access to an invocation context because this isn't a command. You can only use the attributes of the payload, a RawReactionActionEvent object. This includes a guild_id attribute that you can use to get the guild:
#client.event
async def on_raw_reaction_add(payload):
if payload.guild_id is None:
return # Reaction is on a private message
guild = client.get_guild(payload.guild_id)
role = discord.utils.get(guild.roles, name="check-in")
member = guild.get_member(payload.user_id)
if str(payload.channel_id) in check_in:
await member.add_roles(role, reason="check-in")

TypeError: send() takes from 1 to 2 positional arguments but 3 were given

Here is part of code
#client.event
async def on_message(message):
# we do not want the bot to reply to itself
if message.author == client.user:
return
# The command /patch return a link with the latest patch note
if message.content.startswith('/patch'):
await message.channel.send(message.channel, 'Last patchnotes: https://www.epicgames.com/fortnite/en/news')
# The command /rank return attribute a rank according to the K/D of the user
used discord.py
when you type /patch
here's what the console shows
Ignoring exception in on_message
Traceback (most recent call last):
File "C:\Users\FeNka\AppData\Local\Programs\Python\Python37-32\lib\site-packages\discord\client.py", line 227, in _run_event
await coro(*args, **kwargs)
File "bot.py", line 107, in on_message
await message.channel.send(message.channel, 'Last patchnotes: https://www.epicgames.com/fortnite/en/news')
TypeError: send() takes from 1 to 2 positional arguments but 3 were given
What could be wrong?
Your call should be changed to
await message.channel.send('Last patchnotes: https://www.epicgames.com/fortnite/en/news')
send is a function of the message.channel class, and thus has access to self. Its call probably looks something like:
def send(self, message):
#does things
self is implicit here, you don't send it, and that's why it looks like 2 args were passed when 3 actually were sent

Discord.py change_nickname error too many arguments

I am currently trying to make a command with discord.py to reset all user nicknames on a server (!!!mreset). However I'm getting a type error which tells me 4 arguments were given.
Code:
#client.event
async def on_message(message):
  if message.author == client.user:
     return
  if message.content.startswith('!!!mreset'):
     serverid = message.server.id
     x = message.server.members
     for member in x:
       await client.change_nickname(serverid, member.name, None)
Error:
Ignoring exception in on_message
Traceback (most recent call last):
File "C:\Users\Saber\PycharmProjects\my_bot\venv\lib\site-packages\discord\client.py", line 307, in _run_event
yield from getattr(self, event)(*args, **kwargs)
File "C:/Users/Saber/PycharmProjects/my_bot/my_bot.py", line 32, in on_message
await client.change_nickname(serverid, member.name, None)
TypeError: change_nickname() takes 3 positional arguments but 4 were given
You don't need to pass the serverid, or a Server object to change_nickname. Member objects have a server associated with them, so the command can get the appropriate Server from the Member object. You should also be passing a Member object and not the Member.name attribute.
if message.content.startswith('!!!mreset'):
for member in message.server.members:
        await client.change_nickname(member, None)

Discord-py Move member

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)

Categories

Resources