0
所以我完成了大部分我想爲我的不和機器人實現的命令。C# - 當某些短語被說出時(不是前綴命令),有不和諧的機器人執行功能
< [Group(「GroupName」)]>功能非常簡單易懂,更易於理解更新的Discord.NET。然而,與0.9.6版本不同,我不知道如何讓機器人執行一個功能,而無需等待前綴被註冊。 進入這裏
public async Task HandleCommand(SocketMessage messageParam)
{
// Don't process the command if it was a System Message
var message = messageParam as SocketUserMessage;
if (message == null) return;
// Create a number to track where the prefix ends and the command begins
int argPos = 0;
// Determine if the message is a command, based on if it starts with '!' or a mention prefix
if (!(message.HasCharPrefix('$', ref argPos) || message.HasMentionPrefix(client.CurrentUser, ref argPos))) return;
// Create a Command Context
var context = new CommandContext(client, message);
// Execute the command. (result does not indicate a return value,
// rather an object stating if the command executed successfully)
var result = await commands.ExecuteAsync(context, argPos, services);
if (!result.IsSuccess)
await context.Channel.SendMessageAsync(result.ErrorReason);
}
代碼從Foxbot引導直複製粘貼。現在我明白它在註冊命令之前要等待'$'或者@bot提及。
我想要做的是讓機器人能夠尋找特定的網頁網址(http://archiveofourown.org/),並且在沒有用戶請求的情況下加載網頁並打印出網頁中的某些元素。