2 回答
TA贡献1809条经验 获得超8个赞
这是我为使其正常工作而制作的示例:
import discord
from discord.ext import commands
ignoredChannels = [] # List of all the ignored channels, you can use a text file instead if you prefer
client = discord.ext.commands.Bot(command_prefix = "fg!");
@client.event
async def on_message(message):
if message.channel.id in ignoredChannels:
return # If the channel is in the ignored list - return
else:
await client.process_commands(message) # Otherwise process the commands
@client.command()
async def ignore(ctx, channelID):
if int(channelID) not in ignoredChannels:
ignoredChannels.append(int(channelID)) # Add the channel if it hasn't been added yet
await ctx.send("Successfully added the channel to the ignored list!")
else:
await ctx.send("Channel was already inside the ignored list!") # Otherwise warn user that the channel is already ignored
@client.command()
async def unignore(ctx, channelID):
try:
ignoredChannels.remove(int(channelID)) # Attempt to remove the channel from the list
await ctx.send("Successfully removed the channel from the ignored list!")
except:
await ctx.send("This channel is already removed!") # If fails, warn the user that the channel is already removed
client.run(your_bot_token) # Run the bot with your token
它是如何工作的,每次发送消息时,它都会检查列表中是否存在频道 ID,如果它在列表中找到该频道,它将返回,否则什么都不做,如果该频道不在列表中,它将继续处理该通道中的命令。
如果您只想允许管理员使用您可以@commands.has_permissions(administrator=True)在每一行下添加的命令@client.command()。
希望它有所帮助并祝您编码愉快:)
添加回答
举报