python - 需要帮助 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'])
解决方案
推荐阅读
- ios - 在 UIStackView 上添加 UITextField 时应用程序崩溃
- regex - 在电话正则表达式中添加换行符
- javascript - 使用 html 标记更改数组中的元素,然后显示该数组
- ios - 从 Xcode 10 更新到 Xcode 11.3.1 时出现 Xcode 编译器错误
- python - 在 pyqt5 中退出 GUI 时终止正在运行的进程的正确方法是什么?
- postgresql - 禁用 PostgreSQL 查询优化?
- python - 我如何对从 FTP 服务器下载的 tensorflow 模型使用 .predict 方法?
- java - 登录表单:单击按钮时键盘隐藏,但单击edittext后不再显示
- arrays - 在Google表格中提取单词和字符之间的单词
- sql - 强制 dbGetQuery 返回 POSIXct 时间戳