Reputation: 601
As the title suggests, I want to add a command to my bot which would DM someone an invite to the server. Using a static link which is permanent is not an option because I want the command to be available across different servers.
This is what I have so far:
@BSL.command(pass_context = True)
async def invite(ctx, userToInvite):
inviteLinq = await BSL.create_invite(destination = ctx.message.channel, xkcd = True, max_uses = 1)
await BSL.send_message(userToInvite, inviteLinq)
However, I get an error InvalidArgument: Destination must be Channel, PrivateChannel, User, or Object. Received str
. I understand that this is due to the fact that the messages in discord are saved as strings.
Is there a way to make it so that you can specify the ID of an user and they receive the invite link in DMs?
Upvotes: 2
Views: 6200
Reputation: 60994
Your userToInvite
is a string, but it should be a User
object. You should use Server.get_member_named
to get the Member
object from the server. Something like
@BSL.command(pass_context = True)
async def invite(ctx, userToInvite):
inviteLinq = await BSL.create_invite(destination = ctx.message.channel, xkcd = True, max_uses = 1)
target_member = await ctx.message.server.get_member_named(userToInvite)
await BSL.send_message(target_member, inviteLinq)
EDIT:
If you're inviting a user to this server using their id, you should instead try
@BSL.command(pass_context = True)
async def invite(ctx, userToInvite):
inviteLinq = await BSL.create_invite(destination = ctx.message.server, xkcd = True, max_uses = 1)
target_user = await BSL.get_user_info(userToInvite)
await BSL.send_message(target_member, inviteLinq)
Upvotes: 2