只有机器人开发人员才能使用的代码是什么?

时间:2018-06-18 12:06:23

标签: c# discord

我不知道如果我也告诉它,如果机器人只发出货币,而不是不和谐服务器上的其他管理员。

[Command("give"), Alias("Give", "gift", "Gift"), Summary("Used to give or gift people golden coins")]
public async Task Give(IUser User = null, int Amount = 0)
{
    SocketGuildUser User1 = Context.User as SocketGuildUser;
    if (!User1.GuildPermissions.Administrator)
    {
        await Context.Channel.SendMessageAsync($":x: You don't have administrator permissions In this discord server! Ask a moderator or the owner to execute this command!");
        return;
    }
}

1 个答案:

答案 0 :(得分:0)

只需在命令顶部添加[RequireOwner]属性即可。

[RequireOwner]
[Command("give"), Alias("Give", "gift", "Gift"), Summary("Used to give or gift people golden coins")]
public async Task Give(IUser User = null, int Amount = 0)
{
    SocketGuildUser User1 = Context.User as SocketGuildUser;
    //Give currency to the user.
}

如果执行此命令的人是Bot的所有者(您),该属性将让命令服务为您检查。如果命令不是来自机器人所有者,它将忽略该命令。