Discord Bot Kick Command

时间:2017-09-23 10:34:29

标签: python discord discord.py

我如何使用角色设置kick命令只使用主持人角色可以使用 我的踢命令:

@client.command(pass_context = True)
async def kick(ctx, userName: discord.User):
    """Kick A User from server"""
    await client.kick(userName)
    await client.say("__**Successfully User Has Been Kicked!**__")

1 个答案:

答案 0 :(得分:1)

您可以使用commands.has_permissions装饰器来确保来电者具有特定权限。

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/activity_main"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:background="#f4f7f9"
    tools:context=".MainActivity">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">


    <LinearLayout
        android:id="@+id/linearLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"

        android:layout_alignParentTop="true"
        android:layout_alignParentStart="true"
        android:weightSum="1">
        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal">
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Logout"
                android:textSize="22sp"
                android:textColor="#DF0713"
                android:id="@+id/logout_text"
                android:layout_toLeftOf="@+id/logout"
                android:layout_marginRight="10dp"
                android:layout_marginTop="3dp"/>
        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/logout"
         android:layout_alignParentEnd="true"
            android:background="@drawable/logout"/>
        </RelativeLayout>

        <android.support.design.widget.TextInputLayout
            android:layout_width="match_parent"

            android:layout_height="wrap_content">

            <EditText
                android:id="@+id/description"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginBottom="10dp"
                android:hint="Image Title"
                android:inputType="textEmailAddress"
                android:textColor="@color/colorPrimaryDark"
                android:textColorHint="@color/colorPrimaryDark" />
        </android.support.design.widget.TextInputLayout>


        <ImageView
            android:id="@+id/imageView"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"

            android:layout_marginTop="10dp" />


    </LinearLayout>





    <android.support.design.widget.FloatingActionButton
        android:id="@+id/floatingActionButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"

        android:layout_marginBottom="17dp"
        android:layout_marginEnd="17dp"
        android:clickable="true"
        app:fabSize="normal"
android:layout_below="@+id/linearLayout"
        app:backgroundTint="#DF0713"
        app:srcCompat="@drawable/splash"
        android:layout_alignParentBottom="true"
        android:layout_alignParentEnd="true"
        app:borderWidth="0dp"
        app:elevation="0dp"
        />
    </RelativeLayout>
</ScrollView>

只是提醒一下,根据函数docstring,它会检查具有任何所需权限的用户,而不是 all
还建议添加bot_has_permissions检查,以确保它实际上也可以踢用户。