首页 > 解决方案 > 需要帮助 discord bot 命令

问题描述

我最近才开始学习 python,以前从未编写过不和谐的机器人。我一直试图让机器人连接到语音或响应">hello",但它没有响应我的命令,我不知道如何修复它。我正在使用replit作为托管。

import discord
import os
from discord.ext import commands

intents = discord.Intents.default()
intents.members = True
client = commands.Bot(command_prefix = '>', intents=intents)

@client.event
async def on_ready():
  print('Log in as {0.user}'.format(client))
  print('-------------------')

@client.command()
async def hello(ctx):
    await ctx.send("Hello Im Deemo Bot")

@client.command(pass_context = True)
async def join(ctx):
  if (ctx.author.voice):
    channel = ctx.message.author.voice.channel
    await channel.connect()
  else:
    await ctx.send('You are not in a voice channel')

@client.command(pass_context = True)
async def leave(ctx):
  if (ctx.voice_client):
    await ctx.guild.voice_client.disconnect()
    await ctx.send('Deemo left voice')
  else:
    await ctx.send('Deemo is not in voice')

keep_alive()
client.run(os.environ['TOKEN'])

标签: pythondiscord.py

解决方案


推荐阅读