EchoTheAlpha
EchoTheAlpha

Reputation: 422

How to discord invite link with DIscord.py

is there a way i can create a invite link using Discord.PY? My code is the following/

import discord
from discord.ext import commands
import pickle


client = commands.Bot("-")

@client.event

async def on_message(message):
    message.content.lower()
    if message.author == client.user:
        return
#checks if the bot it running.
    if message.content.startswith("message"):
        await message.channel.send("hello there")
#tells the user where they are.
    if message.content.startswith("whereami"):
        await message.channel.send(f"You are in {message.guild.name} " + \
            f"in the {message.channel.mention} channel!")
    ##Creates Instant Invite
    if message.content.startswith("createinvite"):
        await create_invite(*, reason=None, **fields)
        await message.channel.send("Here is an instant invite to your server: " + link)
client.run('token')

If needed, let me know what other information you need, and if i need to edit this to make it more clear. If I need to import anything else, please inform me as to what libraries are needed.

Upvotes: 0

Views: 1266

Answers (2)

igeN
igeN

Reputation: 1

Is there a way to create one, but only with one use? i have an on_message event: if someone type xy, the bot will kick him. and after the kick i want to send him an xy message.(its ready) and after this i want to send him an invite

Upvotes: 0

Diggy.
Diggy.

Reputation: 6944

@client.event
async def on_message(message):
    if message.content.lower().startswith("createinvite"):
        invite = await message.channel.create_invite()
        await message.channel.send(f"Here's your invite: {invite}")

And using command decorators:

@client.command()
async def createinvite(ctx):
    invite = await ctx.channel.create_invite()
    await ctx.send(f"Here's your invite: {invite}")

References:

Upvotes: 1

Related Questions