一個IT宅男

简单实现Discord机器人命令监听

import discord
from discord.ext import commands

#创建一个Bot实例(用于获取授权链接)

intents = discord.Intents.default()
intents.typing = False
intents.presences = False
intents.message_content = True

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

@bot.event
async def on_ready():
print(f'Logged in as {bot.user.name}')

@bot.command()
async def get_auth_link(ctx):
# 替换以下信息为你在Discord开发者门户中设置的信息
print('command')
client_id = '1163921945558011954'
redirect_uri = 'https://yourwebsite.com/discord-callback'
scopes = ['identify', 'guilds', 'messages.read']

# 生成授权链接
auth_link = discord.utils.oauth_url(client_id, scopes=scopes, redirect_uri=redirect_uri)

await ctx.send(f'Click this link to authorize the bot: {auth_link}')

#运行Bot

bot.run('你的token')

效果就是在discord中(bot必须在里面)输入!get_auth_link,就执行async def get_auth_link(ctx):

赞(0)
未經允許不得轉載:Lincai Chen's Blog » 简单实现Discord机器人命令监听

評論 抢沙发