首页 > 解决方案 > 只有机器人的开发人员才能使用的代码是什么?

问题描述

如果我也告诉它,我不确定如何让机器人只发放货币,而不是不和谐服务器上的其他管理员。

[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;
    }
}

标签: c#discord

解决方案


只需[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 的所有者(您),该属性将让命令服务为您检查。如果不是来自 bot owner ,它将忽略该命令。


推荐阅读