所以,我一直试图为我为Discord创作的机器人创建一个禁止的单词列表,我一直在遇到麻烦但根本没有工作。
以下是我尝试过的代码。
public static string fileName1 = "banned_words.txt";
if (e.Message.RawText.Contains(File.ReadLines(fileName1).ToString()))
{
e.Message.Delete();
Console.WriteLine(e.User.Name + " said " + e.Message.RawText.Clone());
e.Channel.SendMessage(e.User.Mention + " Please do not use that language!");
}
答案 0 :(得分:0)
您正在询问来自的消息是否包含整个banned_words列表,其中IEnumerable
字符串转换为字符串,该字符串可能是字面值“IEnumerable``String
”或类似的表示形式。
您应该一次查看banned_words.txt文件中的每个字符串,并检查消息是否一次只包含一个字符串:
foreach (string badWord in File.ReadLines(fileName1)) {
if (e.Message.RawText.Contains(badWord)) {
//Do stuff
}
}
答案 1 :(得分:0)
除了Tim所说的,你可以通过简单地比较两个大写单词来使它不区分大小写,例如。
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@page import="java.util.ArrayList,java.util.List" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Course Learning Objectives to Student Outcomes Mapper</title>
</head>
<body>
<h1>Course Learning Objectives to Student Outcomes Mapper</h1>
<c:choose>
<c:when test="${empty id}">
<form method="get" action="CLOtoSO">
<select name="id">
<c:forEach items="${CourseIdMap}" var="Course">
<option value="${Course.value}">${Course.key}</option>
</c:forEach>
</select>
<input type="submit" value="Select" />
</form>
</c:when>
<c:otherwise>
<table border="1">
<tr>
<td> </td>
<c:forEach items="${SOIdsMap}" var="SOId">
<td title="${SODescriptionsMap[SOId.value]}">${SOId.key}</td>
</c:forEach>
</tr>
<c:forEach items="${CLODescriptionsMap}" var="CLODescription">
<tr>
<td>${CLODescription.value}</td>
<c:forEach items="${SOIdsMap}" var="SOId">
<td><select form="CLOtoSOform" name="map-${SOId.value}_${CLODescription.key}">
<option value="-">-</option>
<option value="R">R</option>
<option value="I">I</option>
<option value="A">A</option>
</select></td>
</c:forEach>
</tr>
</c:forEach>
</table>
<form method="post" action="CLOtoSO" id="CLOtoSOform">
<input type="hidden" name="id" value="${id}">
<input type="submit" value="Update" />
</form>
</c:otherwise>
</c:choose>
</body>
</html>