python - 我如何退出或中断 discord.py 中的命令
问题描述
我想知道是否有办法在匹配条件时中断命令
例如,当用户不是管理员时,我想打破这个命令
@client.command
async def test_me(ctx):
user = ctx.author.id
if user not in admins:
await ctx.send("you're not admin")
break command
else:
None
await ctx.send('Hi admin')
所以我不想在 if 语句中添加整个内容,这就是我问的原因
解决方案
你不能break
一个函数。else
您需要在循环中使用break,如果它为空,您也不需要该语句。
如果您只想退出该功能,您可以使用return
像这样的东西应该工作
@client.command
async def test_me(ctx):
user = ctx.author.id
if user not in admins:
await ctx.send("you're not admin")
return
await ctx.send('Hi admin')
推荐阅读
- python - 使用 Python driver.current_url 语句获取 Selenium 自动化的完整 URL
- c# - 如何完全终止 EXCEL.exe 在 office.interop 中运行的任务?
- nginx - NGINX 错误地将请求转发到默认位置
- java - SonarLint 在 VSCode 上缺少 Java 规则
- firebase - 类型错误:firebase.initializeApp 不是函数。(在 'firebase.initializeApp(firebaseConfig)' 中,'firebase.initializeApp' 未定义)
- python - 是否有 python 库来创建 github pull-request
- typescript - Typescript如何将类型键映射到camelCase
- java - 将 maven java 项目部署到 WildFly 时遇到错误
- python - 无法打开 lib 'SQL Server Native Client 10.0' Python3,Linux ubuntu
- laravel - Laravel 的 Eloquent 和 Raw 查询的不同结果