【发布时间】:2020-10-13 10:46:48
【问题描述】:
我想知道管理员想要在哪些文本频道中启用我的机器人功能。但在这种情况下,我的代码不起作用。
主要想法是当管理员在文本聊天中输入!enable 时,机器人会对其做出反应并将文本聊天 id、公会 id(ctx.channel.id) 添加到列表中,然后机器人在与bot has been enabled 的聊天中做出响应。
此命令不起作用的代码:
channel = []
@bot.command()
async def enable(ctx):
global channel
print("Debug")
await ctx.send('Restriction bot has been enabled for this text channel.')
channel.append(ctx.channel.id)
完整的机器人代码:
import discord
from discord.ext import commands
bot = commands.Bot(command_prefix='!')
@bot.event
async def on_ready():
print(f'We have logged in as {bot.user.name}.')
channel = []
@bot.command()
async def enable(ctx):
global channel
print("Debug")
await ctx.send('Restriction bot has been enabled for this text channel.')
channel.append(ctx.channel.id)
@bot.event
async def on_message(ctx):
if ctx.author == bot.user:
return
#if ctx.channel.id != [for channnels in channel]:
# return
if ctx.attachments[0].height:
await ctx.author.send('Your media file is restricted!')
await ctx.delete()
【问题讨论】:
标签: python-3.x discord.py discord.py-rewrite