[英]How to check if owner in discord.py
我正在嘗試使這個命令只有所有者才能運行它。 無論如何要檢查最高角色或服務器的創建者嗎?
我試過 '@commands.is_owner()' 但它只檢查某人是否是機器人的所有者。
Guild.owner
存在,所以這里有一個使用示例!
from discord.ext import commands
bot = commands.Bot(command_prefix="your_prefix")
# example use with custom decorator
def guild_owner_only():
async def predicate(ctx):
return ctx.author == ctx.guild.owner # checks if author is the owner
return commands.check(predicate)
@bot.command()
@guild_owner_only()
async def ...
您可以使用裝飾器:
@commands.has_role("RoleName")
例子:
import discord
from discord.ext import commands
from discord.ext.commands.core import command
@bot.command
@commands.has_role("RoleName")
async def ...(ctx)
await ctx.send("your message")
讓我知道它是否有效!
編輯:您還可以導入所有內容:
import discord
from discord import user
from discord.ext import commands
from discord.ext.commands.core import command
from discord.member import Member
from discord.message import Message
from discord.user import User
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.