Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Discord Bot in python creating an invite link and dming it to a user

I am making a Discord Bot in Python(3.7.3) and I would like to send a dm to a user with an invite link to the server. This is my code:

import discord
from discord.ext import commands

bot = commands.Bot(command_prefix=config.get_config, description='Thou Holy Bot')

@bot.command(name='dm',pass_context=True)
async def dm(ctx, *, argument):
    <code here>

I have a discord.member.Member() class. And I would like to make an invite link to a channel(a have a channel object if that's needed) and dm it to a user. Any help is appreciated, thanks!

like image 477
ScottBot10 Avatar asked Dec 07 '25 05:12

ScottBot10


1 Answers

Thanks to everyone who helped me I have found a solution.

import discord
from discord.ext import commands

bot = commands.Bot(command_prefix='!', description='Bot')

@bot.command(name='dm',pass_context=True)
async def dm(ctx, *argument):
    #creating invite link
    invitelink = await ctx.channel.create_invite(max_uses=1,unique=True)
    #dming it to the person
    await ctx.author.send(invitelink)

Here is the documentation create_invite documentation

like image 98
ScottBot10 Avatar answered Dec 08 '25 19:12

ScottBot10



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!