有没有一种方法可以使用Discord.PY创建邀请链接?我的代码如下/
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')
如果需要,请让我知道您还需要什么其他信息,以及是否需要对其进行编辑以使其更加清晰。如果我需要导入其他任何内容,请告知我需要哪些库。
答案 0 :(得分:1)
@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}")
并使用命令修饰符:
@client.command()
async def createinvite(ctx):
invite = await ctx.channel.create_invite()
await ctx.send(f"Here's your invite: {invite}")
参考: