c# - 只有机器人的开发人员才能使用的代码是什么?
问题描述
如果我也告诉它,我不确定如何让机器人只发放货币,而不是不和谐服务器上的其他管理员。
[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;
}
}
解决方案
只需[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 ,它将忽略该命令。
推荐阅读
- python - 试图在 pygame 中旋转图像以进行移动
- python - seaborn.jointplot() 中的参数
- python - 从元组列表中过滤掉整数
- javascript - JavaScript display 属性只影响前 3 个元素
- c++ - No compile_commands.json file using cmake with vs code on windows
- python - 无法在此处确定问题
- javascript - 如何在本机反应中创建“全局状态”,以便将用户输入发送到另一个页面?
- ios - 为什么在swift iOS中使用MFMailComposeViewController时会自动调用didFinishWith委托方法?
- angular - 如何构建 Spring Boot 微服务
- c - 基于 LinkedList 的队列,创建新队列时不能返回空指针